Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorAntonio Vazquez <blendergit@gmail.com>2022-08-02 10:46:32 +0300
committerPhilipp Oeser <info@graphics-engineer.com>2022-09-22 10:14:58 +0300
commit345cdf71e96ed4c26307417565154b57fc588884 (patch)
tree23b72144b25f47baad35de3d58e1cbeb4192b82e /source
parentdba599c8064731df4b68b7e983fba1ce2d41c4eb (diff)
GPencil: Allow import several SVG at time
For SVG is very convenient to be able to import several SVG in one operation. Each SVG is imported as a new Grease Pencil object. Also, now the SVG file name is used as Object name. Important: As all SVG imported are converted to Grease Pencil object in the same location of the 3D cursor, the SVG imported are not moved and the result may require a manual fix of location. The same is applied for depth order, the files are imported in alphabetic order according to the File list. Reviewed By: mendio, pepeland Differential Revision: https://developer.blender.org/D14865
Diffstat (limited to 'source')
-rw-r--r--source/blender/editors/io/io_gpencil_import.c45
-rw-r--r--source/blender/io/gpencil/gpencil_io.h2
-rw-r--r--source/blender/io/gpencil/intern/gpencil_io_import_base.cc17
3 files changed, 49 insertions, 15 deletions
diff --git a/source/blender/editors/io/io_gpencil_import.c b/source/blender/editors/io/io_gpencil_import.c
index 9ac64407dcf..b6fecfaf94e 100644
--- a/source/blender/editors/io/io_gpencil_import.c
+++ b/source/blender/editors/io/io_gpencil_import.c
@@ -9,6 +9,8 @@
# include "BLI_path_util.h"
+# include "MEM_guardedalloc.h"
+
# include "DNA_gpencil_types.h"
# include "DNA_space_types.h"
@@ -63,7 +65,8 @@ static int wm_gpencil_import_svg_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
- if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
+ if (!RNA_struct_property_is_set(op->ptr, "filepath") ||
+ !(RNA_struct_find_property(op->ptr, "directory"))) {
BKE_report(op->reports, RPT_ERROR, "No filename given");
return OPERATOR_CANCELLED;
}
@@ -75,9 +78,6 @@ static int wm_gpencil_import_svg_exec(bContext *C, wmOperator *op)
}
View3D *v3d = get_invoke_view3d(C);
- char filename[FILE_MAX];
- RNA_string_get(op->ptr, "filepath", filename);
-
/* Set flags. */
int flag = 0;
@@ -101,13 +101,31 @@ static int wm_gpencil_import_svg_exec(bContext *C, wmOperator *op)
.resolution = resolution,
};
- /* Do Import. */
- WM_cursor_wait(1);
- const bool done = gpencil_io_import(filename, &params);
- WM_cursor_wait(0);
-
- if (!done) {
- BKE_report(op->reports, RPT_WARNING, "Unable to import SVG");
+ /* Loop all selected files to import them. All SVG imported shared the same import
+ * parameters, but they are created in separated grease pencil objects. */
+ PropertyRNA *prop;
+ if ((prop = RNA_struct_find_property(op->ptr, "directory"))) {
+ char *directory = RNA_string_get_alloc(op->ptr, "directory", NULL, 0, NULL);
+
+ if ((prop = RNA_struct_find_property(op->ptr, "files"))) {
+ char file_path[FILE_MAX];
+ RNA_PROP_BEGIN (op->ptr, itemptr, prop) {
+ char *filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0, NULL);
+ BLI_join_dirfile(file_path, sizeof(file_path), directory, filename);
+ MEM_freeN(filename);
+
+ /* Do Import. */
+ WM_cursor_wait(1);
+ RNA_string_get(&itemptr, "name", params.filename);
+ const bool done = gpencil_io_import(file_path, &params);
+ WM_cursor_wait(0);
+ if (!done) {
+ BKE_reportf(op->reports, RPT_WARNING, "Unable to import '%s'", file_path);
+ }
+ }
+ RNA_PROP_END;
+ }
+ MEM_freeN(directory);
}
return OPERATOR_FINISHED;
@@ -149,10 +167,11 @@ void WM_OT_gpencil_import_svg(wmOperatorType *ot)
ot->check = wm_gpencil_import_svg_common_check;
WM_operator_properties_filesel(ot,
- FILE_TYPE_OBJECT_IO,
+ FILE_TYPE_FOLDER | FILE_TYPE_OBJECT_IO,
FILE_BLENDER,
FILE_OPENFILE,
- WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH | WM_FILESEL_SHOW_PROPS,
+ WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH | WM_FILESEL_SHOW_PROPS |
+ WM_FILESEL_DIRECTORY | WM_FILESEL_FILES,
FILE_DEFAULTDISPLAY,
FILE_SORT_DEFAULT);
diff --git a/source/blender/io/gpencil/gpencil_io.h b/source/blender/io/gpencil/gpencil_io.h
index 215891e3e48..eb811fa2de8 100644
--- a/source/blender/io/gpencil/gpencil_io.h
+++ b/source/blender/io/gpencil/gpencil_io.h
@@ -35,6 +35,8 @@ typedef struct GpencilIOParams {
/** Stroke sampling factor. */
float stroke_sample;
int32_t resolution;
+ /** Filename to be used in new objects. */
+ char filename[128];
} GpencilIOParams;
/* GpencilIOParams->flag. */
diff --git a/source/blender/io/gpencil/intern/gpencil_io_import_base.cc b/source/blender/io/gpencil/intern/gpencil_io_import_base.cc
index 9b00fbaa027..18cbbceda0b 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_import_base.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_import_base.cc
@@ -14,6 +14,7 @@
#include "BKE_material.h"
#include "ED_gpencil.h"
+#include "ED_object.h"
#include "gpencil_io_import_base.hh"
@@ -27,10 +28,22 @@ GpencilImporter::GpencilImporter(const GpencilIOParams *iparams) : GpencilIO(ipa
Object *GpencilImporter::create_object()
{
- const float *cur = scene_->cursor.location;
+ const float *cur_loc = scene_->cursor.location;
+ const float rot[3] = {0.0f};
ushort local_view_bits = (params_.v3d && params_.v3d->localvd) ? params_.v3d->local_view_uuid :
(ushort)0;
- Object *ob_gpencil = ED_gpencil_add_object(params_.C, cur, local_view_bits);
+
+ Object *ob_gpencil = ED_object_add_type(params_.C,
+ OB_GPENCIL,
+ (params_.filename != nullptr) ? params_.filename :
+ nullptr,
+ cur_loc,
+ rot,
+ false,
+ local_view_bits);
+
+ /* Set object defaults. */
+ ED_gpencil_add_defaults(params_.C, ob_gpencil);
return ob_gpencil;
}