[Bf-blender-cvs] [4e897f23c7a] greasepencil-object: GPencil: Prepare IO operator project
Antonio Vazquez
noreply at git.blender.org
Sat Jul 25 16:33:27 CEST 2020
Commit: 4e897f23c7ab64ec65f75c256d62416b4d5150f6
Author: Antonio Vazquez
Date: Thu Jul 23 17:06:30 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rB4e897f23c7ab64ec65f75c256d62416b4d5150f6
GPencil: Prepare IO operator project
This is just an empty structure
===================================================================
M source/blender/editors/io/CMakeLists.txt
A source/blender/editors/io/io_gpencil.c
A source/blender/editors/io/io_gpencil.h
M source/blender/editors/io/io_ops.c
===================================================================
diff --git a/source/blender/editors/io/CMakeLists.txt b/source/blender/editors/io/CMakeLists.txt
index e7effd05d34..a50aa40ea86 100644
--- a/source/blender/editors/io/CMakeLists.txt
+++ b/source/blender/editors/io/CMakeLists.txt
@@ -39,12 +39,14 @@ set(SRC
io_alembic.c
io_cache.c
io_collada.c
+ io_gpencil.c
io_ops.c
io_usd.c
io_alembic.h
io_cache.h
io_collada.h
+ io_gpencil.h
io_ops.h
io_usd.h
)
@@ -79,4 +81,6 @@ if(WITH_INTERNATIONAL)
add_definitions(-DWITH_INTERNATIONAL)
endif()
+list(APPEND LIB bf_gpencil)
+
blender_add_lib(bf_editor_io "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
diff --git a/source/blender/editors/io/io_gpencil.c b/source/blender/editors/io/io_gpencil.c
new file mode 100644
index 00000000000..92a0e0bac37
--- /dev/null
+++ b/source/blender/editors/io/io_gpencil.c
@@ -0,0 +1,245 @@
+/*
+ * 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.
+ *
+ * The Original Code is Copyright (C) 2020 Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup editor/io
+ */
+
+/* needed for directory lookup */
+#ifndef WIN32
+# include <dirent.h>
+#else
+# include "BLI_winstuff.h"
+#endif
+
+#include <errno.h>
+#include <string.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_mesh_types.h"
+#include "DNA_modifier_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_space_types.h"
+
+#include "BKE_context.h"
+#include "BKE_global.h"
+#include "BKE_main.h"
+#include "BKE_report.h"
+
+#include "BLI_listbase.h"
+#include "BLI_math_vector.h"
+#include "BLI_path_util.h"
+#include "BLI_string.h"
+#include "BLI_utildefines.h"
+
+#include "BLT_translation.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+#include "RNA_enum_types.h"
+
+#include "ED_object.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "io_gpencil.h"
+
+static int wm_gpencil_export_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ UNUSED_VARS(event);
+
+#if 0
+ if (!RNA_struct_property_is_set(op->ptr, "as_background_job")) {
+ RNA_boolean_set(op->ptr, "as_background_job", true);
+ }
+
+ RNA_boolean_set(op->ptr, "init_scene_frame_range", true);
+
+ if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
+ Main *bmain = CTX_data_main(C);
+ char filepath[FILE_MAX];
+
+ if (BKE_main_blendfile_path(bmain)[0] == '\0') {
+ BLI_strncpy(filepath, "untitled", sizeof(filepath));
+ }
+ else {
+ BLI_strncpy(filepath, BKE_main_blendfile_path(bmain), sizeof(filepath));
+ }
+
+ BLI_path_extension_replace(filepath, sizeof(filepath), ".abc");
+ RNA_string_set(op->ptr, "filepath", filepath);
+ }
+
+ WM_event_add_fileselect(C, op);
+#endif
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+static int wm_gpencil_export_exec(bContext *C, wmOperator *op)
+{
+#if 0
+
+ if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
+ BKE_report(op->reports, RPT_ERROR, "No filename given");
+ return OPERATOR_CANCELLED;
+ }
+
+ char filename[FILE_MAX];
+ RNA_string_get(op->ptr, "filepath", filename);
+
+ struct GpencilExportParams params = {
+ .frame_start = RNA_int_get(op->ptr, "start"),
+ .frame_end = RNA_int_get(op->ptr, "end"),
+ };
+
+ /* 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
+
+ return OPERATOR_FINISHED;
+}
+
+static void ui_gpencil_export_settings(uiLayout *layout, PointerRNA *imfptr)
+{
+#if 0
+
+ uiLayout *box, *row, *col, *sub;
+
+ 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);
+
+ col = uiLayoutColumn(box, false);
+
+ sub = uiLayoutColumn(col, true);
+ uiItemR(sub, imfptr, "start", 0, IFACE_("Frame Start"), ICON_NONE);
+ uiItemR(sub, imfptr, "end", 0, IFACE_("End"), ICON_NONE);
+#endif
+}
+
+static void wm_gpencil_export_draw(bContext *C, wmOperator *op)
+{
+#if 0
+
+ PointerRNA ptr;
+
+ RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr);
+
+ /* Conveniently set start and end frame to match the scene's frame range. */
+ Scene *scene = CTX_data_scene(C);
+
+ if (scene != NULL && RNA_boolean_get(&ptr, "init_scene_frame_range")) {
+ RNA_int_set(&ptr, "start", SFRA);
+ RNA_int_set(&ptr, "end", EFRA);
+
+ RNA_boolean_set(&ptr, "init_scene_frame_range", false);
+ }
+
+ ui_gpencil_export_settings(op->layout, &ptr);
+#endif
+}
+
+static bool wm_gpencil_export_check(bContext *UNUSED(C), wmOperator *op)
+{
+
+ char filepath[FILE_MAX];
+ RNA_string_get(op->ptr, "filepath", filepath);
+
+ if (!BLI_path_extension_check(filepath, ".svg")) {
+ BLI_path_extension_ensure(filepath, FILE_MAX, ".svg");
+ RNA_string_set(op->ptr, "filepath", filepath);
+ return true;
+ }
+
+ return false;
+}
+
+void WM_OT_gpencil_export(wmOperatorType *ot)
+{
+ ot->name = "Export Gpencil";
+ ot->description = "Export current scene in an Gpencil archive";
+ ot->idname = "WM_OT_gpencil_export";
+
+ ot->invoke = wm_gpencil_export_invoke;
+ ot->exec = wm_gpencil_export_exec;
+ ot->poll = WM_operator_winactive;
+ ot->ui = wm_gpencil_export_draw;
+ ot->check = wm_gpencil_export_check;
+#if 0
+ WM_operator_properties_filesel(ot,
+ FILE_TYPE_FOLDER | FILE_TYPE_ALEMBIC,
+ FILE_BLENDER,
+ FILE_SAVE,
+ WM_FILESEL_FILEPATH | WM_FILESEL_SHOW_PROPS,
+ FILE_DEFAULTDISPLAY,
+ FILE_SORT_ALPHA);
+
+ RNA_def_int(ot->srna,
+ "start",
+ INT_MIN,
+ INT_MIN,
+ INT_MAX,
+ "Start Frame",
+ "Start frame of the export, use the default value to "
+ "take the start frame of the current scene",
+ INT_MIN,
+ INT_MAX);
+
+ RNA_def_int(ot->srna,
+ "end",
+ INT_MIN,
+ INT_MIN,
+ INT_MAX,
+ "End Frame",
+ "End frame of the export, use the default value to "
+ "take the end frame of the current scene",
+ INT_MIN,
+ INT_MAX);
+
+ /* 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
+ * every change, draw update. */
+ RNA_def_boolean(ot->srna, "init_scene_frame_range", false, "", "");
+#endif
+}
diff --git a/source/blender/editors/io/io_gpencil.h b/source/blender/editors/io/io_gpencil.h
new file mode 100644
index 00000000000..b295d531f05
--- /dev/null
+++ b/source/blender/editors/io/io_gpencil.h
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ *
+ * The Original Code is Copyright (C) 2020 Blender Foundation.
+ * All rights reserved.
+ */
+
+#ifndef __IO_GPENCIL_H__
+#define __IO_GPENCIL_H__
+
+/** \file
+ * \ingroup editor/io
+ */
+
+struct wmOperatorType;
+
+void WM_OT_gpencil_export(struct wmOperatorType *ot);
+
+#endif /* __IO_GPENCIL_H__ */
diff --git a/source/blender/editors/io/io_ops.c b/source/blender/editors/io/io_ops.c
index acb511a414d..4f6efea188f 100644
--- a/source/blender/editors/io/io_ops.c
+++ b/source/blender/editors/io/io_ops.c
@@ -38,6 +38,7 @@
#endif
#include "io_cache.h"
+#include "io_gpencil.h"
void ED_operatortypes_io(void)
{
@@ -54,6 +55,8 @@ void ED_operatortypes_io(void)
WM_operatortype_append(WM_OT_usd_export);
#endif
+ WM_operatortype_append(WM_OT_gpencil_export);
+
WM_operatortype_append(CACHEFILE_OT_open);
WM_operatortype_append(CACHEFILE_OT_reload);
}
More information about the Bf-blender-cvs
mailing list