Commit: 7d166ddf2a390946f692d366bf0c77eb3690b8a2
Author: Antonio Vazquez
Date:   Wed Jul 29 10:20:09 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rB7d166ddf2a390946f692d366bf0c77eb3690b8a2

GPencil: reorganize code to make it more C++ish

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

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/io/gpencil/intern/gpencil_io_base.cc 
b/source/blender/io/gpencil/intern/gpencil_io_base.cc
index da65e7d8a8c..d5530913b4e 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_base.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_base.cc
@@ -27,6 +27,7 @@
 #include "BKE_gpencil.h"
 #include "BKE_gpencil_geom.h"
 #include "BKE_main.h"
+#include "BKE_material.h"
 
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
@@ -35,6 +36,7 @@
 #include "BLI_utildefines.h"
 
 #include "DNA_gpencil_types.h"
+#include "DNA_material_types.h"
 #include "DNA_object_types.h"
 #include "DNA_screen_types.h"
 
@@ -55,6 +57,31 @@ namespace blender {
 namespace io {
 namespace gpencil {
 
+/* Constructor. */
+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.region = params->region;
+  this->params.C = params->C;
+  this->params.filename = params->filename;
+  this->params.mode = params->mode;
+  this->params.flag = params->flag;
+
+  /* Easy access data. */
+  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->winx = params->region->winx;
+  this->winy = params->region->winy;
+
+  /* Prepare output filename with full path. */
+  set_out_filename(params->filename);
+}
+
 /**
  * Set output file input_text full path.
  * \param C: Context.
@@ -71,7 +98,7 @@ void GpencilExporter::set_out_filename(char *filename)
 }
 
 /* Convert to screen space.
- * TODO: Cleanup using a more generic BKE function. */
+ * TODO: Cleanup using a more generic BKE function.?? */
 bool GpencilExporter::gpencil_3d_point_to_screen_space(const float co[3], 
float r_co[2])
 {
   float parent_co[3];
@@ -84,11 +111,11 @@ bool 
GpencilExporter::gpencil_3d_point_to_screen_space(const float co[3], float
       copy_v2_v2(r_co, screen_co);
       /* Invert X axis. */
       if (invert_axis[0]) {
-        r_co[0] = params.region->winx - r_co[0];
+        r_co[0] = winx - r_co[0];
       }
       /* Invert Y axis. */
       if (invert_axis[1]) {
-        r_co[1] = params.region->winy - r_co[1];
+        r_co[1] = winy - r_co[1];
       }
 
       return true;
@@ -99,11 +126,11 @@ bool 
GpencilExporter::gpencil_3d_point_to_screen_space(const float co[3], float
 
   /* Invert X axis. */
   if (invert_axis[0]) {
-    r_co[0] = params.region->winx - r_co[0];
+    r_co[0] = winx - r_co[0];
   }
   /* Invert Y axis. */
   if (invert_axis[1]) {
-    r_co[1] = params.region->winy - r_co[1];
+    r_co[1] = winy - r_co[1];
   }
 
   return false;
@@ -217,6 +244,62 @@ std::string GpencilExporter::to_lower_string(char 
*input_text)
 
   return text;
 }
+
+struct bGPDlayer *GpencilExporter::gpl_current_get(void)
+{
+  return gpl_cur;
+}
+
+void GpencilExporter::gpl_current_set(struct bGPDlayer *gpl)
+{
+  gpl_cur = gpl;
+  BKE_gpencil_parent_matrix_get(depsgraph, params.ob, gpl, diff_mat);
+}
+struct bGPDframe *GpencilExporter::gpf_current_get(void)
+{
+  return gpf_cur;
+}
+
+void GpencilExporter::gpf_current_set(struct bGPDframe *gpf)
+{
+  gpf_cur = gpf;
+}
+struct bGPDstroke *GpencilExporter::gps_current_get(void)
+{
+  return gps_cur;
+}
+
+void GpencilExporter::gps_current_set(struct bGPDstroke *gps)
+{
+  gps_cur = gps;
+  gp_style = BKE_gpencil_material_settings(params.ob, gps->mat_nr + 1);
+  gp_style_current_set(gp_style);
+}
+
+void GpencilExporter::gp_style_current_set(MaterialGPencilStyle *gp_style)
+{
+  this->gp_style = gp_style;
+  is_stroke = ((gp_style->flag & GP_MATERIAL_STROKE_SHOW) &&
+               (gp_style->stroke_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH));
+  is_fill = ((gp_style->flag & GP_MATERIAL_FILL_SHOW) &&
+             (gp_style->fill_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH));
+}
+
+struct MaterialGPencilStyle *GpencilExporter::gp_style_current_get(void)
+{
+  return gp_style;
+}
+
+bool GpencilExporter::gp_style_is_stroke(void)
+{
+  return is_stroke;
+}
+
+bool GpencilExporter::gp_style_is_fill(void)
+{
+  return is_fill;
+}
+
 }  // namespace gpencil
 }  // namespace io
 }  // namespace blender
diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.h 
b/source/blender/io/gpencil/intern/gpencil_io_base.h
index e878b1ea80f..3601573026e 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_base.h
+++ b/source/blender/io/gpencil/intern/gpencil_io_base.h
@@ -24,11 +24,7 @@
 
 #include "BLI_path_util.h"
 
-#include "BKE_gpencil.h"
-#include "BKE_material.h"
-
 #include "DNA_defs.h"
-#include "DNA_gpencil_types.h"
 
 #include "gpencil_io_exporter.h"
 
@@ -49,8 +45,8 @@ namespace gpencil {
 class GpencilExporter {
 
  public:
+  GpencilExporter(const struct GpencilExportParams *params);
   virtual bool write(std::string actual_frame) = 0;
-  void set_out_filename(char *filename);
 
   /* Geometry functions. */
   bool gpencil_3d_point_to_screen_space(const float co[3], float r_co[2]);
@@ -73,44 +69,29 @@ class GpencilExporter {
   struct bGPdata *gpd;
   struct Main *bmain;
   struct RegionView3D *rv3d;
+  int winx, winy;
+
+  struct bGPDlayer *gpl_current_get(void);
+  struct bGPDframe *gpf_current_get(void);
+  struct bGPDstroke *gps_current_get(void);
+  struct MaterialGPencilStyle *gp_style_current_get(void);
+  bool gp_style_is_stroke(void);
+  bool gp_style_is_fill(void);
 
-  struct bGPDlayer *gpl_current_get(void)
-  {
-    return gpl_cur;
-  }
-  void gpl_current_set(struct bGPDlayer *gpl)
-  {
-    gpl_cur = gpl;
-    BKE_gpencil_parent_matrix_get(depsgraph, params.ob, gpl, diff_mat);
-  }
-  struct bGPDframe *gpf_current_get(void)
-  {
-    return gpf_cur;
-  }
-  void gpf_current_set(struct bGPDframe *gpf)
-  {
-    gpf_cur = gpf;
-  }
-  struct bGPDstroke *gps_current_get(void)
-  {
-    return gps_cur;
-  }
-  void gps_current_set(struct bGPDstroke *gps)
-  {
-    gps_cur = gps;
-    gp_style = BKE_gpencil_material_settings(params.ob, gps->mat_nr + 1);
-  }
-
-  struct MaterialGPencilStyle *gp_style_current_get(void)
-  {
-    return gp_style;
-  }
+  void gpl_current_set(struct bGPDlayer *gpl);
+  void gpf_current_set(struct bGPDframe *gpf);
+  void gps_current_set(struct bGPDstroke *gps);
+  void gp_style_current_set(MaterialGPencilStyle *gp_style);
 
  private:
   struct bGPDlayer *gpl_cur;
   struct bGPDframe *gpf_cur;
   struct bGPDstroke *gps_cur;
   struct MaterialGPencilStyle *gp_style;
+  bool is_stroke;
+  bool is_fill;
+
+  void set_out_filename(char *filename);
 };
 
 }  // namespace gpencil
diff --git a/source/blender/io/gpencil/intern/gpencil_io_svg.cc 
b/source/blender/io/gpencil/intern/gpencil_io_svg.cc
index 2916474d4aa..ae6ca3c0e62 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_svg.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_svg.cc
@@ -62,26 +62,10 @@ namespace gpencil {
 
 /* Constructor. */
 GpencilExporterSVG::GpencilExporterSVG(const struct GpencilExportParams 
*params)
+    : GpencilExporter(params)
 {
-  this->params.frame_start = params->frame_start;
-  this->params.frame_end = params->frame_end;
-  this->params.ob = params->ob;
-  this->params.region = params->region;
-  this->params.C = params->C;
-  this->params.filename = params->filename;
-  this->params.mode = params->mode;
-  this->params.flag = params->flag;
-
-  /* Easy access data. */
-  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->invert_axis[0] = false;
   this->invert_axis[1] = true;
-
-  /* Prepare output filename with full path. */
-  set_out_filename(params->filename);
 }
 
 /* Main write method for SVG format. */
@@ -107,9 +91,6 @@ bool GpencilExporterSVG::write(std::string actual_frame)
 /* Create document header and main svg node. */
 void GpencilExporterSVG::create_document_header(void)
 {
-  int x = params.region->winx;
-  int y = params.region->winy;
-
   /* Add a custom document declaration node. */
   pugi::xml_node decl = doc.prepend_child(pugi::node_declaration);
   decl.append_attribute("version") = "1.0";
@@ -128,11 +109,11 @@ void GpencilExporterSVG::create_document_header(void)
   main_node.append_attribute("x").set_value("0px");
   main_node.append_attribute("y").set_value("0px");
 
-  std::string width = std::to_string(x) + "px";
-  std::string height = std::to_string(y) + "px";
+  std::string width = std::to_string(winx) + "px";
+  std::string height = std::to_string(winy) + "px";
   main_node.append_attribute("width").set_value(width.c_str());
   main_node.append_attribute("height").set_value(height.c_str());
-  std::string viewbox = "0 0 " + std::to_string(x) + " " + std::to_string(y);
+  std::string viewbox = "0 0 " + std::to_string(winx) + " " + 
std::to_string(winy);
   main_node.append_attribute("viewBox").set_value(viewbox.c_str());
 }
 
@@ -152,15 +133,11 @@ void GpencilExporterSVG::export_style_list(void)
 
   for (int i = 0; i < mat_len; i++) {
     MaterialGPencilStyle *gp_style = BKE_gpencil_material_settings(ob, i + 1);
-
-    bool is_stroke = ((gp_style->flag & GP_MATERIAL_STROKE_SHOW) &&
-                      (gp_style->stroke_rgba[3] > 
GPENCIL_ALPHA_OPACITY_THRESH));
-    bool is_fill = ((gp_style->flag & GP_MATERIAL_FILL_SHOW) &&
-                    (gp_style->fill_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH));
+    gp_style_current_set(gp_style);
 
     int id = i + 1;
 
-    if (is_stroke) {
+    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);
@@ -172,7 +149,7 @@ void GpencilExporterSVG::export_style_list(void)
       txt.append(out);
     }
 
-    if (is_fill) {
+    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);
@@ -230,11 +207,6 @@ void GpencilExporterSVG::export_layers(void)
         continue;
       }
       gps_current_set(gps);
-      MaterialGPencilStyle *gp_style = gp_style_current_

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to