[Bf-blender-cvs] [9a47f43ddca] greasepencil-object: GPencil: Reorganize code
Antonio Vazquez
noreply at git.blender.org
Sun Aug 2 13:18:06 CEST 2020
Commit: 9a47f43ddca0f0238bbc84eae09403cf95683b17
Author: Antonio Vazquez
Date: Sun Aug 2 12:34:03 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rB9a47f43ddca0f0238bbc84eae09403cf95683b17
GPencil: Reorganize code
===================================================================
M source/blender/editors/io/io_gpencil.c
M source/blender/io/gpencil/gpencil_io_exporter.h
M source/blender/io/gpencil/intern/gpencil_io_capi.cc
M source/blender/io/gpencil/intern/gpencil_io_svg.cc
===================================================================
diff --git a/source/blender/editors/io/io_gpencil.c b/source/blender/editors/io/io_gpencil.c
index d9fddeb3704..b870e2f9db7 100644
--- a/source/blender/editors/io/io_gpencil.c
+++ b/source/blender/editors/io/io_gpencil.c
@@ -125,28 +125,9 @@ static View3D *get_invoke_view3d(bContext *C)
return NULL;
}
-static bool is_keyframe_empty(bGPdata *gpd, int framenum)
-{
- LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
- if (gpl->flag & GP_LAYER_HIDE) {
- continue;
- }
- LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
- if (gpf->framenum == framenum) {
- return false;
- }
- }
- }
- return true;
-}
-
static int wm_gpencil_export_exec(bContext *C, wmOperator *op)
{
- Main *bmain = CTX_data_main(C);
- Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
Object *ob = CTX_data_active_object(C);
- Object *ob_eval_ = (Object *)DEG_get_evaluated_id(depsgraph, &ob->id);
- bGPdata *gpd_eval = (bGPdata *)ob_eval_->data;
if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
BKE_report(op->reports, RPT_ERROR, "No filename given");
@@ -174,6 +155,7 @@ static int wm_gpencil_export_exec(bContext *C, wmOperator *op)
/* Set flags. */
int flag = 0;
+ SET_FLAG_FROM_TEST(flag, only_active_frame, GP_EXPORT_ACTIVE_FRAME);
SET_FLAG_FROM_TEST(flag, use_fill, GP_EXPORT_FILL);
SET_FLAG_FROM_TEST(flag, use_norm_thickness, GP_EXPORT_NORM_THICKNESS);
SET_FLAG_FROM_TEST(flag, use_selected_objects, GP_EXPORT_SELECTED_OBJECTS);
@@ -200,31 +182,11 @@ static int wm_gpencil_export_exec(bContext *C, wmOperator *op)
params.frame_end = EFRA;
}
- int oldframe = (int)DEG_get_ctime(depsgraph);
- bool done = false;
+ /* Do export. */
+ WM_cursor_wait(1);
+ bool done = gpencil_io_export(¶ms);
+ WM_cursor_wait(0);
- if (only_active_frame) {
- done = gpencil_io_export(¶ms);
- }
- else {
- for (int i = params.frame_start; i < params.frame_end + 1; i++) {
- if (is_keyframe_empty(gpd_eval, i)) {
- continue;
- }
-
- CFRA = i;
- BKE_scene_graph_update_for_newframe(depsgraph, bmain);
- sprintf(params.frame, "%04d", i);
-
- done |= gpencil_io_export(¶ms);
- }
- }
-
- /* Return frame state and DB to original state */
- if (!only_active_frame) {
- CFRA = oldframe;
- BKE_scene_graph_update_for_newframe(depsgraph, bmain);
- }
if (done) {
BKE_report(op->reports, RPT_INFO, "SVG export file created");
}
diff --git a/source/blender/io/gpencil/gpencil_io_exporter.h b/source/blender/io/gpencil/gpencil_io_exporter.h
index 09df8cb9664..20d488231f5 100644
--- a/source/blender/io/gpencil/gpencil_io_exporter.h
+++ b/source/blender/io/gpencil/gpencil_io_exporter.h
@@ -54,19 +54,21 @@ struct GpencilExportParams {
};
typedef enum eGpencilExportParams_Flag {
+ /* Export only active frame. */
+ GP_EXPORT_ACTIVE_FRAME = (1 << 0),
/* Export Filled strokes. */
- GP_EXPORT_FILL = (1 << 0),
+ GP_EXPORT_FILL = (1 << 1),
/* Export normalized thickness. */
- GP_EXPORT_NORM_THICKNESS = (1 << 1),
+ GP_EXPORT_NORM_THICKNESS = (1 << 2),
/* Export all selected objects. */
- GP_EXPORT_SELECTED_OBJECTS = (1 << 2),
+ GP_EXPORT_SELECTED_OBJECTS = (1 << 3),
/* Clip camera area. */
- GP_EXPORT_CLIP_CAMERA = (1 << 3),
+ GP_EXPORT_CLIP_CAMERA = (1 << 4),
/* Gray Scale. */
- GP_EXPORT_GRAY_SCALE = (1 << 4),
+ GP_EXPORT_GRAY_SCALE = (1 << 5),
} eGpencilExportParams_Flag;
-bool gpencil_io_export(const struct GpencilExportParams *params);
+bool gpencil_io_export(struct GpencilExportParams *params);
#ifdef __cplusplus
}
diff --git a/source/blender/io/gpencil/intern/gpencil_io_capi.cc b/source/blender/io/gpencil/intern/gpencil_io_capi.cc
index 1bdb191fd48..eeb018c5cf2 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_capi.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_capi.cc
@@ -20,16 +20,44 @@
#include <stdio.h>
-#include "WM_api.h"
+#include "BLI_listbase.h"
+#include "BLI_path_util.h"
+#include "BLI_string.h"
+#include "BLI_utildefines.h"
+
+#include "DNA_gpencil_types.h"
+#include "DNA_space_types.h"
+
+#include "BKE_context.h"
+#include "BKE_gpencil.h"
+#include "BKE_main.h"
+#include "BKE_scene.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
#include "../gpencil_io_exporter.h"
#include "gpencil_io_svg.h"
using blender::io::gpencil::GpencilExporterSVG;
-bool gpencil_io_export(const GpencilExportParams *params)
+static bool is_keyframe_empty(bGPdata *gpd, int framenum)
+{
+ LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
+ if (gpl->flag & GP_LAYER_HIDE) {
+ continue;
+ }
+ LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
+ if (gpf->framenum == framenum) {
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+static bool gpencil_io_export_frame(const GpencilExportParams *params)
{
- WM_cursor_wait(1);
bool result = false;
switch (params->mode) {
@@ -42,7 +70,46 @@ bool gpencil_io_export(const GpencilExportParams *params)
break;
}
- WM_cursor_wait(0);
-
return result;
}
+
+/* Main export entry point function. */
+bool gpencil_io_export(GpencilExportParams *params)
+{
+ Main *bmain = CTX_data_main(params->C);
+ Depsgraph *depsgraph = CTX_data_depsgraph_pointer(params->C);
+ Scene *scene = CTX_data_scene(params->C);
+
+ Object *ob = CTX_data_active_object(params->C);
+ Object *ob_eval_ = (Object *)DEG_get_evaluated_id(depsgraph, &ob->id);
+ bGPdata *gpd_eval = (bGPdata *)ob_eval_->data;
+ const bool only_active_frame = ((params->flag & GP_EXPORT_ACTIVE_FRAME) != 0);
+
+ int oldframe = (int)DEG_get_ctime(depsgraph);
+ bool done = false;
+
+ if (only_active_frame) {
+ done |= gpencil_io_export_frame(params);
+ }
+ else {
+ for (int i = params->frame_start; i < params->frame_end + 1; i++) {
+ if (is_keyframe_empty(gpd_eval, i)) {
+ continue;
+ }
+
+ CFRA = i;
+ BKE_scene_graph_update_for_newframe(depsgraph, bmain);
+ sprintf(params->frame, "%04d", i);
+
+ done |= gpencil_io_export_frame(params);
+ }
+ }
+
+ /* Return frame state and DB to original state */
+ if (!only_active_frame) {
+ CFRA = oldframe;
+ BKE_scene_graph_update_for_newframe(depsgraph, bmain);
+ }
+
+ return done;
+}
diff --git a/source/blender/io/gpencil/intern/gpencil_io_svg.cc b/source/blender/io/gpencil/intern/gpencil_io_svg.cc
index bcef9db97a2..9571d42f0d5 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_svg.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_svg.cc
@@ -66,6 +66,12 @@ GpencilExporterSVG::GpencilExporterSVG(const struct GpencilExportParams *iparams
{
invert_axis_[0] = false;
invert_axis_[1] = true;
+
+ /* Calc selected object boundbox. */
+ selected_objects_boundbox();
+
+ rcti boundbox;
+ get_select_boundbox(&boundbox);
}
/* Main write method for SVG format. */
More information about the Bf-blender-cvs
mailing list