IO: Add file handlers to c++ import operators #116873

Merged
Jesse Yurkovich merged 18 commits from guishe/blender:io-fh into main 2024-01-27 23:38:55 +01:00
Contributor

Adds file handlers for the C++ import operators.
This will allow these operators to be invoked with drag-and-drop
filepath data in the 3D Viewport or the Outliner.

When the operators are called with drag-and-drop data a dialog popup
will be used instead of invoking the file select window.

Previously OPTYPE_REGISTER tag had no effect, now since these operators
can run as popup dialogs this flag is removed to prevent heavy io
operations in the redo panel.

Also includes drawing functions for ply and stl and a missing
event notifications to collada import.

Important: Presets can override file path properties, so if a preset is
used, file paths provided by drag and drop will be lost. This will be
addressed in follow up changes.

Adds file handlers for the C++ import operators. This will allow these operators to be invoked with drag-and-drop filepath data in the 3D Viewport or the Outliner. When the operators are called with drag-and-drop data a dialog popup will be used instead of invoking the file select window. Previously OPTYPE_REGISTER tag had no effect, now since these operators can run as popup dialogs this flag is removed to prevent heavy io operations in the redo panel. Also includes drawing functions for ply and stl and a missing event notifications to collada import. Important: Presets can override file path properties, so if a preset is used, file paths provided by drag and drop will be lost. This will be addressed in follow up changes.
Guillermo Venegas added 1 commit 2024-01-07 18:48:08 +01:00
Iliya Katushenock added this to the Pipeline, Assets & IO project 2024-01-07 19:04:45 +01:00
Jesse Yurkovich requested changes 2024-01-07 23:30:38 +01:00
Jesse Yurkovich left a comment
Member

I'll be able to take a closer look tomorrow but left a few minor comments now.

I'll be able to take a closer look tomorrow but left a few minor comments now.
@ -719,0 +723,4 @@
namespace blender::ed::io {
void alembic_file_handler_add()
{
auto fh_ptr = std::make_unique<blender::bke::FileHandlerType>();

I think this can just be auto fh = std::make_unique ... and use fh-> to access the fields. The usage of unique_ptr in blender typically doesn't make a distinction between the ptr and the actual data, especially in cases like this where there would be no confusion, so this just seems like extra ceremony.

I think this can just be `auto fh = std::make_unique ...` and use `fh->` to access the fields. The usage of unique_ptr in blender typically doesn't make a distinction between the `ptr` and the actual data, especially in cases like this where there would be no confusion, so this just seems like extra ceremony.
guishe marked this conversation as resolved
@ -287,0 +310,4 @@
{
auto fh_ptr = std::make_unique<blender::bke::FileHandlerType>();
auto &fh = *fh_ptr;
STRNCPY(fh.idname, "IO_FH_slt");

slt -> stl here and in the label below.

`slt` -> `stl` here and in the `label` below.
guishe marked this conversation as resolved
@ -830,0 +837,4 @@
auto &fh = *fh_ptr;
STRNCPY(fh.idname, "IO_FH_usd");
STRNCPY(fh.import_operator, "WM_OT_usd_import");
STRNCPY(fh.label, "USD");

As much as possible, try to use labels that match what's shown in the current File->Import menu. So this should at least be "Universal Scene Description" (see also the PLY and gpencil changes). Ideally the strings wouldn't be duplicated at all but haven't thought about how to do that easily right now.

As much as possible, try to use labels that match what's shown in the current `File`->`Import` menu. So this should at least be "Universal Scene Description" (see also the PLY and gpencil changes). Ideally the strings wouldn't be duplicated at all but haven't thought about how to do that easily right now.
Author
Contributor

Should include .ext?
Also I'm not sure if is Wavefront OBJ or just Wavefront for obj

Should include .ext? Also I'm not sure if is `Wavefront OBJ` or just `Wavefront` for obj

Also I'm not sure if is Wavefront OBJ or just Wavefront for obj

I think it's the other way around, if you have to drop a word, drop the "wavefront" but leave OBJ by all means. Almost no one knows what "wavefront" means or what it stands for these days.

> Also I'm not sure if is `Wavefront OBJ` or just `Wavefront` for obj I think it's the other way around, if you have to drop a word, drop the "wavefront" but leave OBJ by all means. Almost no one knows what "wavefront" means or what it stands for these days.
guishe marked this conversation as resolved
Guillermo Venegas added 1 commit 2024-01-08 02:04:26 +01:00
Author
Contributor

Yikes, doing Import -> USD for example, the import window won't reuse the last import location.
It was possible because those props did not have PROP_SKIP_SAVE
But that's necessary to avoid overriding filepath props from drag-n-drop.
Edit: Maybe store this last location in the fh?

Yikes, doing `Import -> USD` for example, the import window won't reuse the last import location. It was possible because those props did not have `PROP_SKIP_SAVE` But that's necessary to avoid overriding filepath props from drag-n-drop. Edit: Maybe store this last location in the fh?
Guillermo Venegas requested review from Jesse Yurkovich 2024-01-09 16:22:19 +01:00
Hans Goudey reviewed 2024-01-09 17:24:52 +01:00
@ -0,0 +1,87 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
Member

Looks like this file is missing copyright info

Looks like this file is missing copyright info
guishe marked this conversation as resolved
@ -0,0 +46,4 @@
if (SpaceFile *sfile = CTX_wm_space_file(C); sfile && sfile->op == op) {
return;
}
/**
Member

Comments within a function generally don't get the doxygen styling-- the first line will be on the same line as /*

Comments within a function generally don't get the doxygen styling-- the first line will be on the same line as `/*`
guishe marked this conversation as resolved
@ -0,0 +1,29 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
Member

Copyright here too

Copyright here too
guishe marked this conversation as resolved
Guillermo Venegas added 1 commit 2024-01-09 18:09:35 +01:00
Guillermo Venegas reviewed 2024-01-09 20:14:38 +01:00
@ -0,0 +44,4 @@
}
/* Check if the operator is running in 3D viewport or the outliner, if so, that means that the
* operator is running as a dialog popup. */
const View3D *v3d = CTX_wm_view3d(C);
Author
Contributor

I wonder if the OP_IS_INVOKE flag can be used here to make this test here
Because creating the operator in #116646
for drawing probably won't set this flag
People may want add export collection panel to the npanel

I wonder if the `OP_IS_INVOKE` flag can be used here to make this test here Because creating the operator in https://projects.blender.org/blender/blender/pulls/116646 for drawing probably won't set this flag People may want add export collection panel to the npanel
guishe marked this conversation as resolved

Yikes, doing Import -> USD for example, the import window won't reuse the last import location.
It was possible because those props did not have PROP_SKIP_SAVE
But that's necessary to avoid overriding filepath props from drag-n-drop.
Edit: Maybe store this last location in the fh?

Right, we should keep the existing user experience. Is there a downside to allowing drag-n-drop to override that path? Said another way, why is drag-n-drop considered different than File->Import? Modify the same filepath property during both operations.

I wonder if the OP_IS_INVOKE flag can be used here to make this test here
Because creating the operator in #116646
for drawing probably won't set this flag
People may want add export collection panel to the npanel

Is there a reason the drawing of the "file label" (the filepath or files property) needs to be part of the Operator's draw instead of being part of the dialog popup draw?

> Yikes, doing `Import -> USD` for example, the import window won't reuse the last import location. > It was possible because those props did not have `PROP_SKIP_SAVE` > But that's necessary to avoid overriding filepath props from drag-n-drop. > Edit: Maybe store this last location in the fh? Right, we should keep the existing user experience. Is there a downside to allowing drag-n-drop to override that path? Said another way, why is drag-n-drop considered different than File->Import? Modify the same filepath property during both operations. > I wonder if the `OP_IS_INVOKE` flag can be used here to make this test here > Because creating the operator in https://projects.blender.org/blender/blender/pulls/116646 > for drawing probably won't set this flag > People may want add export collection panel to the npanel Is there a reason the drawing of the "file label" (the filepath or files property) needs to be part of the Operator's draw instead of being part of the dialog popup draw?
Author
Contributor

Right, we should keep the existing user experience. Is there a downside to allowing drag-n-drop to override that path? Said another way, why is drag-n-drop considered different than File->Import? Modify the same filepath property during both operations.

Is not the drag-n-drop that overrides the path, if the operator runs as popup dialog because is invoked with drag-n-drop data, using operator presets can override the path given by drag-n-drop:

Currently PROP_SKIP_SAVE only allows to remember last import location, in the import window operator presets can override this filepath but has no true effect since when you click import the file select window will just set the path to the selected file.

Is there a reason the drawing of the "file label" (the filepath or files property) needs to be part of the Operator's draw instead of being part of the dialog popup draw?

Using WM_operator_props_dialog_popup I can't do really to much, it does uses the op->draw func
We can skip draw the filepath at all, but its a nice thing to see

> Right, we should keep the existing user experience. Is there a downside to allowing drag-n-drop to override that path? Said another way, why is drag-n-drop considered different than File->Import? Modify the same filepath property during both operations. Is not the drag-n-drop that overrides the path, if the operator runs as popup dialog because is invoked with drag-n-drop data, using operator presets can override the path given by drag-n-drop: <video src="/attachments/72be36e8-9525-4617-a751-ca115bc1105b" title="2024-01-09 16-49-58.mp4" controls></video> Currently `PROP_SKIP_SAVE` only allows to remember last import location, in the import window operator presets can override this filepath but has no true effect since when you click import the file select window will just set the path to the selected file. >Is there a reason the drawing of the "file label" (the filepath or files property) needs to be part of the Operator's draw instead of being part of the dialog popup draw? Using `WM_operator_props_dialog_popup` I can't do really to much, it does uses the op->draw func We can skip draw the filepath at all, but its a nice thing to see

Ah, Presets are the problem, sorry missed that connection from your description. Presets used to write-out the filepath properties when created! That's somewhat surprising and very unfortunate :( So the new WM_FILESEL_SKIP_SAVE_PROPS flag has 2 effects. It prevents the preset add operator from writing out these properties to the preset file, which means when you apply the preset it doesn't overwrite the path. But it also prevents the properties from being saved altogether of course. If folks already have preset files saved, with the filepath property set, things will still be broken btw.

Unsure how to get past this one at the moment.

As for drawing the filepath label, having to change every importer just for this isn't great. We'd have to expose that to python and teach the ecosystem about what to do as well. We could leave it out OR get our hands dirty and just implement our own form of the WM_operator_props_dialog_popup by using UI_popup_block_ex directly so every importer gets this part of the drawing for free. There's <100 lines of boilerplate required and seems to work locally for me. Ping me on chat if you want the code.

Ah, Presets are the problem, sorry missed that connection from your description. Presets used to write-out the filepath properties when created! That's somewhat surprising and very unfortunate :( So the new `WM_FILESEL_SKIP_SAVE_PROPS` flag has 2 effects. It prevents the preset add operator from writing out these properties to the preset file, which means when you apply the preset it doesn't overwrite the path. But it also prevents the properties from being saved altogether of course. If folks already have preset files saved, with the filepath property set, things will still be broken btw. Unsure how to get past this one at the moment. As for drawing the filepath label, having to change every importer just for this isn't great. We'd have to expose that to python and teach the ecosystem about what to do as well. We could leave it out OR get our hands dirty and just implement our own form of the `WM_operator_props_dialog_popup` by using `UI_popup_block_ex` directly so every importer gets this part of the drawing for free. There's <100 lines of boilerplate required and seems to work locally for me. Ping me on chat if you want the code.
Guillermo Venegas added 4 commits 2024-01-10 19:26:51 +01:00
Guillermo Venegas added 1 commit 2024-01-10 19:34:51 +01:00
Author
Contributor

Move out the dependency in operators filepath properties to reuse last
import location
#116999

~~Move out the dependency in operators filepath properties to reuse last import location #116999~~
Guillermo Venegas added 1 commit 2024-01-11 02:53:52 +01:00
Author
Contributor

@deadpin what about instead of adding a new popup, change the confirm text to
Import file.abc/ Import 7 files
#117143

@deadpin what about instead of adding a new popup, change the confirm text to `Import file.abc`/ `Import 7 files` #117143
Guillermo Venegas added 2 commits 2024-01-15 23:22:42 +01:00
Guillermo Venegas added 2 commits 2024-01-25 17:35:45 +01:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
36cc92b8b3
remove introduced popup

@blender-bot build

@blender-bot build
Guillermo Venegas added 2 commits 2024-01-25 21:30:49 +01:00
Guillermo Venegas added 2 commits 2024-01-26 21:36:25 +01:00
Author
Contributor

image

![image](/attachments/0e8475f8-0128-4c5a-9caa-7000b8f10972)
Guillermo Venegas added 1 commit 2024-01-27 02:28:23 +01:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
39e3b64aee
undo last commit

@blender-bot build

@blender-bot build
Jesse Yurkovich merged commit d4bc3bd08d into main 2024-01-27 23:38:55 +01:00
Guillermo Venegas deleted branch io-fh 2024-01-29 15:56:50 +01:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#116873
No description provided.