[Bf-blender-cvs] [0bb0feeacdb] greasepencil-object: GPencil: Basic creation of XML
Antonio Vazquez
noreply at git.blender.org
Sat Jul 25 16:33:27 CEST 2020
Commit: 0bb0feeacdb852c496e126626812b112bc1403b8
Author: Antonio Vazquez
Date: Thu Jul 23 20:19:19 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rB0bb0feeacdb852c496e126626812b112bc1403b8
GPencil: Basic creation of XML
All parts in place, ready to start to create the export
===================================================================
M source/blender/editors/io/io_gpencil.c
M source/blender/io/gpencil/CMakeLists.txt
M source/blender/io/gpencil/gpencil_io_exporter.h
M source/blender/io/gpencil/intern/gpencil_io_capi.cc
A source/blender/io/gpencil/intern/gpencil_io_svg.cc
A 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 7d2fcfd7561..6b33b508fbe 100644
--- a/source/blender/editors/io/io_gpencil.c
+++ b/source/blender/editors/io/io_gpencil.c
@@ -100,6 +100,7 @@ static int wm_gpencil_export_invoke(bContext *C, wmOperator *op, const wmEvent *
static int wm_gpencil_export_exec(bContext *C, wmOperator *op)
{
+ Scene *scene = CTX_data_scene(C);
if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
BKE_report(op->reports, RPT_ERROR, "No filename given");
@@ -108,25 +109,15 @@ static int wm_gpencil_export_exec(bContext *C, wmOperator *op)
char filename[FILE_MAX];
RNA_string_get(op->ptr, "filepath", filename);
+ Object *ob = CTX_data_active_object(C);
struct GpencilExportParams params = {
- .frame_start = RNA_int_get(op->ptr, "start"),
- .frame_end = RNA_int_get(op->ptr, "end"),
+ .frame_start = (params.frame_start == INT_MIN) ? SFRA : RNA_int_get(op->ptr, "start"),
+ .frame_end = (params.frame_end == INT_MIN) ? EFRA : RNA_int_get(op->ptr, "end"),
+ .ob = ob,
};
-#if 0
- /* Take some defaults from the scene, if not specified explicitly. */
- Scene *scene = CTX_data_scene(C);
- if (params.frame_start == INT_MIN) {
- params.frame_start = SFRA;
- }
- if (params.frame_end == INT_MIN) {
- params.frame_end = EFRA;
- }
-
- const bool as_background_job = RNA_boolean_get(op->ptr, "as_background_job");
- bool ok = ABC_export(scene, C, filename, ¶ms, as_background_job);
-#endif
+ gpencil_io_export(C, filename, ¶ms);
return OPERATOR_FINISHED;
}
@@ -139,12 +130,6 @@ static void ui_gpencil_export_settings(uiLayout *layout, PointerRNA *imfptr)
uiLayoutSetPropSep(layout, true);
uiLayoutSetPropDecorate(layout, false);
- // box = uiLayoutBox(layout);
- // uiItemL(box, IFACE_("Manual Transform"), ICON_NONE);
-
- // uiItemR(box, imfptr, "global_scale", 0, NULL, ICON_NONE);
-
- /* Scene Options */
box = uiLayoutBox(layout);
row = uiLayoutRow(box, false);
uiItemL(row, IFACE_("Scene Options"), ICON_SCENE_DATA);
diff --git a/source/blender/io/gpencil/CMakeLists.txt b/source/blender/io/gpencil/CMakeLists.txt
index c6172642078..a74cfbe46d8 100644
--- a/source/blender/io/gpencil/CMakeLists.txt
+++ b/source/blender/io/gpencil/CMakeLists.txt
@@ -41,8 +41,10 @@ set(INC_SYS
set(SRC
intern/gpencil_io_capi.cc
+ intern/gpencil_io_svg.cc
gpencil_io_exporter.h
+ intern/gpencil_io_svg.h
)
set(LIB
diff --git a/source/blender/io/gpencil/gpencil_io_exporter.h b/source/blender/io/gpencil/gpencil_io_exporter.h
index d7c680bca1b..1b9e53e2b16 100644
--- a/source/blender/io/gpencil/gpencil_io_exporter.h
+++ b/source/blender/io/gpencil/gpencil_io_exporter.h
@@ -23,11 +23,20 @@
extern "C" {
#endif
+struct Scene;
+struct bContext;
+
struct GpencilExportParams {
double frame_start;
double frame_end;
+ /** Grease pencil object. */
+ struct Object *ob;
};
+bool gpencil_io_export(struct bContext *C,
+ const char *filepath,
+ const struct GpencilExportParams *params);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/io/gpencil/intern/gpencil_io_capi.cc b/source/blender/io/gpencil/intern/gpencil_io_capi.cc
index b2b2f1af12c..1d90214fa88 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_capi.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_capi.cc
@@ -19,3 +19,14 @@
*/
#include "../gpencil_io_exporter.h"
+#include <stdio.h>
+
+#include "gpencil_io_svg.h"
+
+bool gpencil_io_export(bContext *C, const char *filepath, const GpencilExportParams *params)
+{
+ blender::io::gpencil::GpencilSVGwriter mywriter;
+ mywriter.write(C, filepath, params);
+
+ return true;
+}
diff --git a/source/blender/io/gpencil/intern/gpencil_io_svg.cc b/source/blender/io/gpencil/intern/gpencil_io_svg.cc
new file mode 100644
index 00000000000..cf6e46cad85
--- /dev/null
+++ b/source/blender/io/gpencil/intern/gpencil_io_svg.cc
@@ -0,0 +1,92 @@
+/*
+ * 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 "BKE_context.h"
+#include "BKE_main.h"
+
+#include "BLI_path_util.h"
+#include "BLI_string.h"
+
+#include "DNA_object_types.h"
+
+#ifdef WIN32
+# include "utfconv.h"
+#endif
+
+#include <fstream>
+
+#include "gpencil_io_exporter.h"
+#include "gpencil_io_svg.h"
+
+#include "pugixml.hpp"
+
+namespace blender {
+namespace io {
+namespace gpencil {
+
+/* Constructor. */
+GpencilSVGwriter::GpencilSVGwriter(void)
+{
+ std::cout << "Constructor\n";
+}
+
+bool GpencilSVGwriter::write(struct bContext *C,
+ const char *filepath,
+ const struct GpencilExportParams *params)
+{
+ Main *bmain = CTX_data_main(C);
+ char svg_filename[FILE_MAX];
+ BLI_strncpy(svg_filename, filepath, FILE_MAX);
+ BLI_path_abs(svg_filename, BKE_main_blendfile_path(bmain));
+
+ Object *ob = params->ob;
+
+ //#ifdef WIN32
+ // UTF16_ENCODE(svg_filename);
+ //#endif
+
+ /* Create simple XML. */
+ pugi::xml_document doc;
+
+ // tag::code[]
+ // add node with some name
+ pugi::xml_node node = doc.append_child("node");
+
+ // add description node with text child
+ pugi::xml_node descr = 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 = 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(svg_filename);
+
+ return true;
+}
+
+} // namespace gpencil
+} // namespace io
+} // namespace blender
diff --git a/source/blender/io/gpencil/gpencil_io_exporter.h b/source/blender/io/gpencil/intern/gpencil_io_svg.h
similarity index 70%
copy from source/blender/io/gpencil/gpencil_io_exporter.h
copy to source/blender/io/gpencil/intern/gpencil_io_svg.h
index d7c680bca1b..ece8e4e49a3 100644
--- a/source/blender/io/gpencil/gpencil_io_exporter.h
+++ b/source/blender/io/gpencil/intern/gpencil_io_svg.h
@@ -19,15 +19,20 @@
* \ingroup bgpencil
*/
-#ifdef __cplusplus
-extern "C" {
-#endif
+struct Main;
+struct GpencilExportParams;
-struct GpencilExportParams {
- double frame_start;
- double frame_end;
+namespace blender {
+namespace io {
+namespace gpencil {
+
+class GpencilSVGwriter {
+
+ public:
+ GpencilSVGwriter(void);
+ bool write(struct bContext *C, const char *filepath, const struct GpencilExportParams *params);
};
-#ifdef __cplusplus
-}
-#endif
+} // namespace gpencil
+} // namespace io
+} // namespace blender
More information about the Bf-blender-cvs
mailing list