[Bf-blender-cvs] [3921397201f] greasepencil-object: GPencil: Export all selected objects to SVG
Antonio Vazquez
noreply at git.blender.org
Thu Jul 30 20:41:23 CEST 2020
Commit: 3921397201fd23302533aeefe40f24247400b884
Author: Antonio Vazquez
Date: Thu Jul 30 20:41:13 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rB3921397201fd23302533aeefe40f24247400b884
GPencil: Export all selected objects to SVG
===================================================================
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_base.cc
M source/blender/io/gpencil/intern/gpencil_io_base.h
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 e060fed2a51..c02de908f87 100644
--- a/source/blender/editors/io/io_gpencil.c
+++ b/source/blender/editors/io/io_gpencil.c
@@ -149,16 +149,18 @@ static int wm_gpencil_export_exec(bContext *C, wmOperator *op)
const bool only_active_frame = RNA_boolean_get(op->ptr, "only_active_frame");
const bool use_fill = RNA_boolean_get(op->ptr, "use_fill");
const bool use_norm_thickness = RNA_boolean_get(op->ptr, "use_normalized_thickness");
+ const bool use_selected_objects = RNA_boolean_get(op->ptr, "use_selected_objects");
/* Set flags. */
int flag = 0;
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);
struct GpencilExportParams params = {
.C = C,
.region = region,
- .ob = ob,
+ .obact = ob,
.filename = filename,
.mode = GP_EXPORT_TO_SVG,
.frame_start = RNA_int_get(op->ptr, "start"),
@@ -218,9 +220,13 @@ static void ui_gpencil_export_settings(uiLayout *layout, PointerRNA *imfptr)
uiLayoutSetPropDecorate(layout, false);
box = uiLayoutBox(layout);
+
row = uiLayoutRow(box, false);
uiItemL(row, IFACE_("Scene Options"), ICON_SCENE_DATA);
+ row = uiLayoutRow(box, false);
+ uiItemR(row, imfptr, "use_selected_objects", 0, NULL, ICON_NONE);
+
row = uiLayoutRow(box, false);
uiItemR(row, imfptr, "only_active_frame", 0, NULL, ICON_NONE);
@@ -346,6 +352,11 @@ void WM_OT_gpencil_export(wmOperatorType *ot)
false,
"Normalize",
"Export strokes with constant thickness along the stroke");
+ RNA_def_boolean(ot->srna,
+ "use_selected_objects",
+ true,
+ "All Selected Objects",
+ "Export all selected objects, unselect for export active object only");
/* This dummy prop is used to check whether we need to init the start and
* end frame values to that of the scene's, otherwise they are reset at
diff --git a/source/blender/io/gpencil/gpencil_io_exporter.h b/source/blender/io/gpencil/gpencil_io_exporter.h
index 1d30b4b45de..b1c2af4d287 100644
--- a/source/blender/io/gpencil/gpencil_io_exporter.h
+++ b/source/blender/io/gpencil/gpencil_io_exporter.h
@@ -35,7 +35,7 @@ struct GpencilExportParams {
bContext *C;
ARegion *region;
/** Grease pencil object. */
- struct Object *ob;
+ struct Object *obact;
/** Output filename. */
char *filename;
/** Export mode. */
@@ -55,6 +55,8 @@ typedef enum eGpencilExportParams_Flag {
GP_EXPORT_FILL = (1 << 0),
/* Export normalized thickness. */
GP_EXPORT_NORM_THICKNESS = (1 << 1),
+ /* Export all selected objects. */
+ GP_EXPORT_SELECTED_OBJECTS = (1 << 2),
} eGpencilExportParams_Flag;
bool gpencil_io_export(const struct GpencilExportParams *params);
diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.cc b/source/blender/io/gpencil/intern/gpencil_io_base.cc
index d5530913b4e..2d15e55b430 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_base.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_base.cc
@@ -26,6 +26,7 @@
#include "BKE_context.h"
#include "BKE_gpencil.h"
#include "BKE_gpencil_geom.h"
+#include "BKE_layer.h"
#include "BKE_main.h"
#include "BKE_material.h"
@@ -62,7 +63,7 @@ GpencilExporter::GpencilExporter(const struct GpencilExportParams *params)
{
this->params.frame_start = params->frame_start;
this->params.frame_end = params->frame_end;
- this->params.ob = params->ob;
+ this->params.obact = params->obact;
this->params.region = params->region;
this->params.C = params->C;
this->params.filename = params->filename;
@@ -73,15 +74,31 @@ GpencilExporter::GpencilExporter(const struct GpencilExportParams *params)
this->bmain = CTX_data_main(params->C);
this->depsgraph = CTX_data_depsgraph_pointer(params->C);
this->rv3d = (RegionView3D *)params->region->regiondata;
- this->gpd = (bGPdata *)params->ob->data;
+ this->gpd = (bGPdata *)params->obact->data;
this->winx = params->region->winx;
this->winy = params->region->winy;
/* Prepare output filename with full path. */
set_out_filename(params->filename);
-}
+ /* Load list of selected objects. */
+ ViewLayer *view_layer = CTX_data_view_layer(params->C);
+ LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
+ Object *object = base->object;
+
+ if (object->type != OB_GPENCIL) {
+ continue;
+ }
+ if (((params->flag & GP_EXPORT_SELECTED_OBJECTS) == 0) && (params->obact != object)) {
+ continue;
+ }
+
+ if (base->flag & BASE_SELECTED) {
+ ob_list.push_back(object);
+ }
+ }
+}
/**
* Set output file input_text full path.
* \param C: Context.
@@ -245,6 +262,16 @@ std::string GpencilExporter::to_lower_string(char *input_text)
return text;
}
+int GpencilExporter::ob_idx_get(void)
+{
+ return ob_idx_cur;
+}
+
+void GpencilExporter::ob_idx_set(int idx)
+{
+ ob_idx_cur = idx;
+}
+
struct bGPDlayer *GpencilExporter::gpl_current_get(void)
{
return gpl_cur;
@@ -253,8 +280,9 @@ struct bGPDlayer *GpencilExporter::gpl_current_get(void)
void GpencilExporter::gpl_current_set(struct bGPDlayer *gpl)
{
gpl_cur = gpl;
- BKE_gpencil_parent_matrix_get(depsgraph, params.ob, gpl, diff_mat);
+ BKE_gpencil_parent_matrix_get(depsgraph, params.obact, gpl, diff_mat);
}
+
struct bGPDframe *GpencilExporter::gpf_current_get(void)
{
return gpf_cur;
@@ -269,10 +297,10 @@ struct bGPDstroke *GpencilExporter::gps_current_get(void)
return gps_cur;
}
-void GpencilExporter::gps_current_set(struct bGPDstroke *gps)
+void GpencilExporter::gps_current_set(struct Object *ob, struct bGPDstroke *gps)
{
gps_cur = gps;
- gp_style = BKE_gpencil_material_settings(params.ob, gps->mat_nr + 1);
+ gp_style = BKE_gpencil_material_settings(ob, gps->mat_nr + 1);
gp_style_current_set(gp_style);
}
diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.h b/source/blender/io/gpencil/intern/gpencil_io_base.h
index 3601573026e..4f9d138513a 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_base.h
+++ b/source/blender/io/gpencil/intern/gpencil_io_base.h
@@ -18,9 +18,8 @@
/** \file
* \ingroup bgpencil
*/
-#include <map>
+#include <list>
#include <string>
-#include <vector>
#include "BLI_path_util.h"
@@ -28,9 +27,10 @@
#include "gpencil_io_exporter.h"
+struct ARegion;
struct Depsgraph;
struct Main;
-struct ARegion;
+struct Object;
struct RegionView3D;
struct bGPDlayer;
@@ -61,9 +61,11 @@ class GpencilExporter {
protected:
bool invert_axis[2];
float diff_mat[4][4];
-
GpencilExportParams params;
char out_filename[FILE_MAX];
+
+ std::list<Object *> ob_list;
+
/* Data for easy access. */
struct Depsgraph *depsgraph;
struct bGPdata *gpd;
@@ -77,11 +79,13 @@ class GpencilExporter {
struct MaterialGPencilStyle *gp_style_current_get(void);
bool gp_style_is_stroke(void);
bool gp_style_is_fill(void);
+ int ob_idx_get(void);
void gpl_current_set(struct bGPDlayer *gpl);
void gpf_current_set(struct bGPDframe *gpf);
- void gps_current_set(struct bGPDstroke *gps);
+ void gps_current_set(struct Object *ob, struct bGPDstroke *gps);
void gp_style_current_set(MaterialGPencilStyle *gp_style);
+ void ob_idx_set(int idx);
private:
struct bGPDlayer *gpl_cur;
@@ -90,6 +94,7 @@ class GpencilExporter {
struct MaterialGPencilStyle *gp_style;
bool is_stroke;
bool is_fill;
+ int ob_idx_cur;
void set_out_filename(char *filename);
};
diff --git a/source/blender/io/gpencil/intern/gpencil_io_svg.cc b/source/blender/io/gpencil/intern/gpencil_io_svg.cc
index 0fff64e75fb..02b20f932f0 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_svg.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_svg.cc
@@ -18,6 +18,8 @@
* \ingroup bgpencil
*/
#include <iostream>
+#include <iterator>
+#include <list>
#include <string>
#include "MEM_guardedalloc.h"
@@ -120,45 +122,53 @@ void GpencilExporterSVG::create_document_header(void)
*/
void GpencilExporterSVG::export_style_list(void)
{
- Object *ob = this->params.ob;
- int mat_len = max_ii(1, ob->totcol);
main_node.append_child(pugi::node_comment).set_value("List of materials");
pugi::xml_node style_node = main_node.append_child("style");
style_node.append_attribute("type").set_value("text/css");
-
std::string txt;
- float col[3];
- for (int i = 0; i < mat_len; i++) {
- MaterialGPencilStyle *gp_style = BKE_gpencil_material_settings(ob, i + 1);
- gp_style_current_set(gp_style);
-
- int id = i + 1;
-
- if (gp_style_is_stroke()) {
- char out[128];
- linearrgb_to_srgb_v3_v3(col, gp_style->stroke_rgba);
- std::string stroke_hex = rgb_to_hex(col);
- sprintf(out,
- "\n\t.stylestroke%d{stroke: %s; fill: %s;}",
- id,
- stroke_hex.c_str(),
- stroke_hex.c_str());
- txt.append(out);
- }
+ int ob_idx = 1;
+ std::list<Object *>::iterator it;
+ for (it = ob_list.begin(); it != ob_list.end(); ++it) {
+ Object *ob = (Object *)*it;
+ int mat_len = max_ii(1, ob->totcol);
+
+ float col[3];
+
+ for (int i = 0; i < mat_len; i++) {
+ MaterialGPencilStyle *gp_style = BKE_gpencil_material_settings(ob, i + 1);
+ gp_style_current_set(gp_style);
+
+ int id = i + 1;
+
+ if (gp_style_is_stroke()) {
+ char out[128];
+ linearrgb_to_srgb_v3_v3(col, gp_style->stroke_rgba);
+ std::string stroke_hex = rgb_to_hex(col);
+ sprintf(out,
+ "\n\t.ob%dstylestroke%d{stroke: %s; fill: %s;}",
+ ob_idx,
+ id,
+ stroke_hex.c_str(),
+ stroke_hex.c_str());
+ txt.append(out);
+ }
- if (gp_style_is_fill()) {
- char out[128];
- linearrgb_to_srgb_v3_v3(col, gp_style->fill_rgba);
- std::string stroke_hex = rgb_to_hex(col);
- sprintf(out,
- "\n\t.stylefill%d{stroke: %s; fill: %s; fill-opacity: %f}",
- id,
- st
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list