[Bf-blender-cvs] [151fb02f18b] greasepencil-object: GPencil: Fix size and position issue
Antonio Vazquez
noreply at git.blender.org
Sat Jul 25 16:33:29 CEST 2020
Commit: 151fb02f18bd708a6bef777dda501bfa1a61288a
Author: Antonio Vazquez
Date: Sat Jul 25 12:15:41 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rB151fb02f18bd708a6bef777dda501bfa1a61288a
GPencil: Fix size and position issue
Also, structure code.
===================================================================
M source/blender/editors/io/io_gpencil.c
M source/blender/io/gpencil/CMakeLists.txt
A source/blender/io/gpencil/intern/gpencil_io_base.cc
A source/blender/io/gpencil/intern/gpencil_io_base.h
M source/blender/io/gpencil/intern/gpencil_io_svg.cc
M source/blender/io/gpencil/intern/gpencil_io_svg.h
===================================================================
diff --git a/source/blender/editors/io/io_gpencil.c b/source/blender/editors/io/io_gpencil.c
index 04d93cfc9aa..3f0711e1cef 100644
--- a/source/blender/editors/io/io_gpencil.c
+++ b/source/blender/editors/io/io_gpencil.c
@@ -142,6 +142,8 @@ static int wm_gpencil_export_exec(bContext *C, wmOperator *op)
gpencil_io_export(¶ms);
+ BKE_report(op->reports, RPT_INFO, "SVG export file created");
+
return OPERATOR_FINISHED;
}
diff --git a/source/blender/io/gpencil/CMakeLists.txt b/source/blender/io/gpencil/CMakeLists.txt
index a74cfbe46d8..4874b7fbc12 100644
--- a/source/blender/io/gpencil/CMakeLists.txt
+++ b/source/blender/io/gpencil/CMakeLists.txt
@@ -40,11 +40,13 @@ set(INC_SYS
)
set(SRC
+ intern/gpencil_io_base.cc
intern/gpencil_io_capi.cc
intern/gpencil_io_svg.cc
gpencil_io_exporter.h
intern/gpencil_io_svg.h
+intern/gpencil_io_base.h
)
set(LIB
diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.cc b/source/blender/io/gpencil/intern/gpencil_io_base.cc
new file mode 100644
index 00000000000..f8427397338
--- /dev/null
+++ b/source/blender/io/gpencil/intern/gpencil_io_base.cc
@@ -0,0 +1,98 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup bgpencil
+ */
+#include <iostream>
+#include <string>
+
+#include "BKE_context.h"
+#include "BKE_gpencil.h"
+#include "BKE_main.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_math.h"
+#include "BLI_path_util.h"
+#include "BLI_string.h"
+#include "BLI_utildefines.h"
+
+#ifdef WIN32
+# include "utfconv.h"
+#endif
+
+#include "UI_view2d.h"
+
+#include "ED_view3d.h"
+
+#include "gpencil_io_exporter.h"
+#include "gpencil_io_svg.h"
+
+#include "pugixml.hpp"
+
+namespace blender {
+namespace io {
+namespace gpencil {
+
+void GpencilExporter::set_out_filename(struct bContext *C, char *filename)
+{
+ Main *bmain = CTX_data_main(C);
+ BLI_strncpy(out_filename, filename, FILE_MAX);
+ BLI_path_abs(out_filename, BKE_main_blendfile_path(bmain));
+
+ //#ifdef WIN32
+ // UTF16_ENCODE(svg_filename);
+ //#endif
+}
+
+/* Convert to screen space.
+ * TODO: Cleanup using a more generic BKE function. */
+bool GpencilExporter::gpencil_3d_point_to_screen_space(struct ARegion *region,
+ const float diff_mat[4][4],
+ const float co[3],
+ int r_co[2])
+{
+ float parent_co[3];
+ mul_v3_m4v3(parent_co, diff_mat, co);
+ int screen_co[2];
+ eV3DProjTest test = (eV3DProjTest)(V3D_PROJ_RET_CLIP_BB | V3D_PROJ_RET_CLIP_WIN);
+ if (ED_view3d_project_int_global(region, parent_co, screen_co, test) == V3D_PROJ_RET_OK) {
+ if (!ELEM(V2D_IS_CLIPPED, screen_co[0], screen_co[1])) {
+ copy_v2_v2_int(r_co, screen_co);
+ return true;
+ }
+ }
+ r_co[0] = V2D_IS_CLIPPED;
+ r_co[1] = V2D_IS_CLIPPED;
+ return false;
+}
+
+std::string GpencilExporter::rgb_to_hex(float color[3])
+{
+ int r = color[0] * 255.0f;
+ int g = color[1] * 255.0f;
+ int b = color[2] * 255.0f;
+ char hex_string[20];
+ sprintf(hex_string, "#%02X%02X%02X", r, g, b);
+
+ std::string hexstr = hex_string;
+
+ return hexstr;
+}
+
+} // namespace gpencil
+} // namespace io
+} // namespace blender
diff --git a/source/blender/io/gpencil/intern/gpencil_io_svg.h b/source/blender/io/gpencil/intern/gpencil_io_base.h
similarity index 78%
copy from source/blender/io/gpencil/intern/gpencil_io_svg.h
copy to source/blender/io/gpencil/intern/gpencil_io_base.h
index 14364ac6ba1..bac751b7121 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_svg.h
+++ b/source/blender/io/gpencil/intern/gpencil_io_base.h
@@ -36,29 +36,19 @@ class GpencilExporter {
virtual bool write(void) = 0;
void set_out_filename(struct bContext *C, char *filename);
+ /* Geometry functions. */
+ bool gpencil_3d_point_to_screen_space(struct ARegion *region,
+ const float diff_mat[4][4],
+ const float co[3],
+ int r_co[2]);
+
+ std::string rgb_to_hex(float color[3]);
+
protected:
GpencilExportParams params;
char out_filename[FILE_MAX];
};
-class GpencilExporterSVG : public GpencilExporter {
-
- public:
- ARegion *region;
-
- GpencilExporterSVG(const struct GpencilExportParams *params);
- bool write(void);
-
- private:
- /* XML doc. */
- pugi::xml_document doc;
- /* Main document node. */
- pugi::xml_node main_node;
-
- void create_document_header(void);
- void layers_loop(void);
-};
-
} // namespace gpencil
} // namespace io
} // namespace blender
diff --git a/source/blender/io/gpencil/intern/gpencil_io_svg.cc b/source/blender/io/gpencil/intern/gpencil_io_svg.cc
index 8e226331471..dd125ae7e99 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_svg.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_svg.cc
@@ -26,14 +26,12 @@
#include "BLI_blenlib.h"
#include "BLI_math.h"
-#include "BLI_path_util.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "DNA_gpencil_types.h"
#include "DNA_object_types.h"
#include "DNA_screen_types.h"
-#include "DNA_space_types.h"
#ifdef WIN32
# include "utfconv.h"
@@ -52,24 +50,13 @@ namespace blender {
namespace io {
namespace gpencil {
-void GpencilExporter::set_out_filename(struct bContext *C, char *filename)
-{
- Main *bmain = CTX_data_main(C);
- BLI_strncpy(out_filename, filename, FILE_MAX);
- BLI_path_abs(out_filename, BKE_main_blendfile_path(bmain));
-
- //#ifdef WIN32
- // UTF16_ENCODE(svg_filename);
- //#endif
-}
-
/* Constructor. */
GpencilExporterSVG::GpencilExporterSVG(const struct GpencilExportParams *params)
{
this->params.frame_start = params->frame_start;
this->params.frame_end = params->frame_end;
this->params.ob = params->ob;
- this->region = params->region;
+ this->params.region = params->region;
this->params.C = params->C;
this->params.filename = params->filename;
this->params.mode = params->mode;
@@ -78,47 +65,12 @@ GpencilExporterSVG::GpencilExporterSVG(const struct GpencilExportParams *params)
set_out_filename(params->C, params->filename);
}
-/* Convert to screen space.
- * TODO: Cleanup using a more generic BKE function. */
-static bool gpencil_3d_point_to_screen_space(ARegion *region,
- const float diff_mat[4][4],
- const float co[3],
- int r_co[2])
-{
- float parent_co[3];
- mul_v3_m4v3(parent_co, diff_mat, co);
- int screen_co[2];
- eV3DProjTest test = (eV3DProjTest)(V3D_PROJ_RET_CLIP_BB | V3D_PROJ_RET_CLIP_WIN);
- if (ED_view3d_project_int_global(region, parent_co, screen_co, test) == V3D_PROJ_RET_OK) {
- if (!ELEM(V2D_IS_CLIPPED, screen_co[0], screen_co[1])) {
- copy_v2_v2_int(r_co, screen_co);
- return true;
- }
- }
- r_co[0] = V2D_IS_CLIPPED;
- r_co[1] = V2D_IS_CLIPPED;
- return false;
-}
-
/* Main write method for SVG format. */
bool GpencilExporterSVG::write(void)
{
create_document_header();
layers_loop();
- //// add description node with text child
- // pugi::xml_node descr = main_node.append_child("object");
- // descr.append_child(pugi::node_pcdata).set_value(ob->id.name + 2);
-
- //// add param node before the description
- // pugi::xml_node param = main_node.insert_child_before("param", descr);
-
- //// add attributes to param node
- // param.append_attribute("name") = "version";
- // param.append_attribute("value") = 1.1;
- // param.insert_attribute_after("type", param.attribute("name")) = "float";
-
- // end::code[]
doc.save_file(out_filename);
return true;
@@ -127,7 +79,8 @@ bool GpencilExporterSVG::write(void)
/* Create document header and main svg node. */
void GpencilExporterSVG::create_document_header(void)
{
- Scene *scene = CTX_data_scene(params.C);
+ 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);
@@ -146,18 +99,22 @@ void GpencilExporterSVG::create_document_header(void)
main_node.append_attribute("version").set_value("1.0");
main_node.append_attribute("x").set_value("0px");
main_node.append_attribute("y").set_value("0px");
- main_node.append_attribute("width").set_value(std::to_string(scene->r.xsch).c_str());
- main_node.append_attribute("height").set_value(std::to_string(scene->r.ysch).c_str());
- std::string viewbox = "0 0 " + std::to_string(scene->r.xsch) + " " +
- std::to_string(scene->r.ysch);
+
+ std::string width = std::to_string(x) + "px";
+ std::string height = std::to_string(y) + "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);
main_node.append_attribute("viewBox").set_value(viewbox.c_str());
}
/* Main layer loop. */
void GpencilExporterSVG::layers_loop(void)
{
+ float color[3] = {1.0f, 0.5f, 0.01f};
+ std::string hex = rgb_to_hex(color);
+
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(params.C);
- Scene *scene = CTX_data_scene(params.C);
Object *ob = params.ob;
bGPdata *gpd = (bGPdata *)ob->data;
@@ -189,13 +146,16 @@ void GpencilExporterSVG::layers_loop(void)
}
bGPDspoint *pt = &gps->points[i];
int screen_co[2];
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list