From 1b8c14b4539af1a2c8846e4054b108dc3002e15e Mon Sep 17 00:00:00 2001 From: Tamito Kajiyama Date: Sun, 20 Nov 2011 23:44:50 +0000 Subject: Replaced the changes in revision 41810 with a better implementation of copy/paste functionality. Instead of making a copy of the active line set, now the settings of the active line set are copied to and pasted from a buffer. This allows for copying and pasting line set settings among different scenes and render layers. --- release/scripts/startup/bl_ui/properties_render.py | 3 +- source/blender/editors/render/render_intern.h | 1 + source/blender/editors/render/render_ops.c | 1 + source/blender/editors/render/render_shading.c | 30 +++++++++- source/blender/freestyle/FRS_freestyle.h | 1 + .../intern/blender_interface/FRS_freestyle.cpp | 66 +++++++++++++++++----- 6 files changed, 87 insertions(+), 15 deletions(-) diff --git a/release/scripts/startup/bl_ui/properties_render.py b/release/scripts/startup/bl_ui/properties_render.py index 2f1e5b9a529..85b5f3f0dd4 100644 --- a/release/scripts/startup/bl_ui/properties_render.py +++ b/release/scripts/startup/bl_ui/properties_render.py @@ -180,7 +180,8 @@ class RENDER_MT_lineset_specials(Menu): def draw(self, context): layout = self.layout - layout.operator("scene.freestyle_lineset_copy", icon='ZOOMIN') + layout.operator("scene.freestyle_lineset_copy", icon='COPYDOWN') + layout.operator("scene.freestyle_lineset_paste", icon='PASTEDOWN') class RENDER_PT_freestyle(RenderButtonsPanel, Panel): diff --git a/source/blender/editors/render/render_intern.h b/source/blender/editors/render/render_intern.h index dfb30238d0c..0af46eb0129 100644 --- a/source/blender/editors/render/render_intern.h +++ b/source/blender/editors/render/render_intern.h @@ -58,6 +58,7 @@ void SCENE_OT_freestyle_module_remove(struct wmOperatorType *ot); void SCENE_OT_freestyle_module_move(struct wmOperatorType *ot); void SCENE_OT_freestyle_lineset_add(struct wmOperatorType *ot); void SCENE_OT_freestyle_lineset_copy(struct wmOperatorType *ot); +void SCENE_OT_freestyle_lineset_paste(struct wmOperatorType *ot); void SCENE_OT_freestyle_lineset_remove(struct wmOperatorType *ot); void SCENE_OT_freestyle_lineset_move(struct wmOperatorType *ot); void SCENE_OT_freestyle_linestyle_new(struct wmOperatorType *ot); diff --git a/source/blender/editors/render/render_ops.c b/source/blender/editors/render/render_ops.c index 8acb92b1193..f94d94178a4 100644 --- a/source/blender/editors/render/render_ops.c +++ b/source/blender/editors/render/render_ops.c @@ -67,6 +67,7 @@ void ED_operatortypes_render(void) WM_operatortype_append(SCENE_OT_freestyle_module_move); WM_operatortype_append(SCENE_OT_freestyle_lineset_add); WM_operatortype_append(SCENE_OT_freestyle_lineset_copy); + WM_operatortype_append(SCENE_OT_freestyle_lineset_paste); WM_operatortype_append(SCENE_OT_freestyle_lineset_remove); WM_operatortype_append(SCENE_OT_freestyle_lineset_move); WM_operatortype_append(SCENE_OT_freestyle_linestyle_new); diff --git a/source/blender/editors/render/render_shading.c b/source/blender/editors/render/render_shading.c index 1343eb2947d..b3817002b2c 100644 --- a/source/blender/editors/render/render_shading.c +++ b/source/blender/editors/render/render_shading.c @@ -718,7 +718,7 @@ void SCENE_OT_freestyle_lineset_copy(wmOperatorType *ot) /* identifiers */ ot->name= "Copy Line Set"; ot->idname= "SCENE_OT_freestyle_lineset_copy"; - ot->description="Create a copy of the active line set"; + ot->description="Copy the active line set to a buffer"; /* api callbacks */ ot->exec= freestyle_lineset_copy_exec; @@ -727,6 +727,34 @@ void SCENE_OT_freestyle_lineset_copy(wmOperatorType *ot) /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } + +static int freestyle_lineset_paste_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + SceneRenderLayer *srl = (SceneRenderLayer*) BLI_findlink(&scene->r.layers, scene->r.actlay); + + FRS_paste_active_lineset(&srl->freestyleConfig); + + WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene); + + return OPERATOR_FINISHED; +} + +void SCENE_OT_freestyle_lineset_paste(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Paste Line Set"; + ot->idname= "SCENE_OT_freestyle_lineset_paste"; + ot->description="Paste the buffer content to the active line set"; + + /* api callbacks */ + ot->exec= freestyle_lineset_paste_exec; + ot->poll= freestyle_active_lineset_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + static int freestyle_lineset_remove_exec(bContext *C, wmOperator *UNUSED(op)) { Scene *scene= CTX_data_scene(C); diff --git a/source/blender/freestyle/FRS_freestyle.h b/source/blender/freestyle/FRS_freestyle.h index 376663e0a21..6c1f7d454ba 100644 --- a/source/blender/freestyle/FRS_freestyle.h +++ b/source/blender/freestyle/FRS_freestyle.h @@ -67,6 +67,7 @@ extern "C" { FreestyleLineSet *FRS_add_lineset(FreestyleConfig *config); void FRS_copy_active_lineset(FreestyleConfig *config); + void FRS_paste_active_lineset(FreestyleConfig *config); void FRS_delete_active_lineset(FreestyleConfig *config); void FRS_move_active_lineset_up(FreestyleConfig *config); void FRS_move_active_lineset_down(FreestyleConfig *config); diff --git a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp index d85ab0b6e82..fe02406801a 100644 --- a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp +++ b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp @@ -40,6 +40,10 @@ extern "C" { static Controller *controller = NULL; static AppView *view = NULL; + // line set buffer for copy & paste + static FreestyleLineSet lineset_buffer; + static bool lineset_copied = false; + // camera information float freestyle_viewpoint[3]; float freestyle_mv[4][4]; @@ -66,6 +70,7 @@ extern "C" { controller->setView(view); controller->Clear(); freestyle_scene = NULL; + lineset_copied = false; default_module_path = pathconfig->getProjectDir() + Config::DIR_SEP + "style_modules" + Config::DIR_SEP + "contour.py"; @@ -542,6 +547,11 @@ extern "C" { BLI_insertlinkafter(&config->modules, module_conf->next, module_conf); } + static void unique_lineset_name(FreestyleConfig *config, FreestyleLineSet *lineset) + { + BLI_uniquename(&config->linesets, lineset, "FreestyleLineSet", '.', offsetof(FreestyleLineSet, name), sizeof(lineset->name)); + } + FreestyleLineSet *FRS_add_lineset(FreestyleConfig *config) { int lineset_index = BLI_countlist(&config->linesets); @@ -557,12 +567,13 @@ extern "C" { lineset->qi_start = 0; lineset->qi_end = 100; lineset->edge_types = FREESTYLE_FE_SILHOUETTE | FREESTYLE_FE_BORDER | FREESTYLE_FE_CREASE; + lineset->exclude_edge_types = 0; lineset->group = NULL; if (lineset_index > 0) sprintf(lineset->name, "LineSet %i", lineset_index+1); else strcpy(lineset->name, "LineSet"); - BLI_uniquename(&config->linesets, lineset, "FreestyleLineSet", '.', offsetof(FreestyleLineSet, name), sizeof(lineset->name)); + unique_lineset_name(config, lineset); return lineset; } @@ -572,20 +583,49 @@ extern "C" { FreestyleLineSet *lineset = FRS_get_active_lineset(config); if (lineset) { - FreestyleLineSet *new_lineset = FRS_add_lineset(config); - new_lineset->linestyle = lineset->linestyle; - new_lineset->linestyle->id.us++; - new_lineset->flags = lineset->flags; - new_lineset->selection = lineset->selection; - new_lineset->qi = lineset->qi; - new_lineset->qi_start = lineset->qi_start; - new_lineset->qi_end = lineset->qi_end; - new_lineset->edge_types = lineset->edge_types; + lineset_buffer.linestyle = lineset->linestyle; + lineset_buffer.flags = lineset->flags; + lineset_buffer.selection = lineset->selection; + lineset_buffer.qi = lineset->qi; + lineset_buffer.qi_start = lineset->qi_start; + lineset_buffer.qi_end = lineset->qi_end; + lineset_buffer.edge_types = lineset->edge_types; + lineset_buffer.exclude_edge_types = lineset->exclude_edge_types; + lineset_buffer.group = lineset->group; + strcpy(lineset_buffer.name, lineset->name); + lineset_copied = true; + } + } + + void FRS_paste_active_lineset(FreestyleConfig *config) + { + if (!lineset_copied) + return; + + FreestyleLineSet *lineset = FRS_get_active_lineset(config); + + if (lineset) { + lineset->linestyle->id.us--; + lineset->linestyle = lineset_buffer.linestyle; + lineset->linestyle->id.us++; + lineset->flags = lineset_buffer.flags; + lineset->selection = lineset_buffer.selection; + lineset->qi = lineset_buffer.qi; + lineset->qi_start = lineset_buffer.qi_start; + lineset->qi_end = lineset_buffer.qi_end; + lineset->edge_types = lineset_buffer.edge_types; + lineset->exclude_edge_types = lineset_buffer.exclude_edge_types; if (lineset->group) { - new_lineset->group = lineset->group; - new_lineset->group->id.us++; + lineset->group->id.us--; + lineset->group = NULL; + } + if (lineset_buffer.group) { + lineset->group = lineset_buffer.group; + lineset->group->id.us++; } - new_lineset->flags |= FREESTYLE_LINESET_CURRENT; + strcpy(lineset->name, lineset_buffer.name); + unique_lineset_name(config, lineset); + lineset->flags |= FREESTYLE_LINESET_CURRENT; } } -- cgit v1.2.3