Changeset View
Standalone View
source/blender/editors/space_view3d/space_view3d.c
| Show All 40 Lines | |||||
| #include "BLT_translation.h" | #include "BLT_translation.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_curve.h" | #include "BKE_curve.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_icons.h" | #include "BKE_icons.h" | ||||
| #include "BKE_idprop.h" | #include "BKE_idprop.h" | ||||
| #include "BKE_lattice.h" | #include "BKE_lattice.h" | ||||
| #include "BKE_layer.h" | |||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_mball.h" | #include "BKE_mball.h" | ||||
| #include "BKE_mesh.h" | #include "BKE_mesh.h" | ||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "BKE_scene.h" | #include "BKE_scene.h" | ||||
| #include "BKE_screen.h" | #include "BKE_screen.h" | ||||
| #include "BKE_workspace.h" | #include "BKE_workspace.h" | ||||
| #include "ED_object.h" | #include "ED_object.h" | ||||
| #include "ED_outliner.h" | |||||
| #include "ED_render.h" | #include "ED_render.h" | ||||
| #include "ED_screen.h" | #include "ED_screen.h" | ||||
| #include "ED_space_api.h" | #include "ED_space_api.h" | ||||
| #include "ED_transform.h" | #include "ED_transform.h" | ||||
| #include "GPU_matrix.h" | #include "GPU_matrix.h" | ||||
| #include "DRW_engine.h" | #include "DRW_engine.h" | ||||
| ▲ Show 20 Lines • Show All 448 Lines • ▼ Show 20 Lines | static bool view3d_drop_id_in_main_region_poll(bContext *C, | ||||
| return WM_drag_is_ID_type(drag, id_type); | return WM_drag_is_ID_type(drag, id_type); | ||||
| } | } | ||||
| static bool view3d_ob_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event) | static bool view3d_ob_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event) | ||||
| { | { | ||||
| return view3d_drop_id_in_main_region_poll(C, drag, event, ID_OB); | return view3d_drop_id_in_main_region_poll(C, drag, event, ID_OB); | ||||
| } | } | ||||
| static bool view3d_ob_drop_poll_external_asset(bContext *C, wmDrag *drag, const wmEvent *event) | |||||
| { | |||||
| if (!view3d_ob_drop_poll(C, drag, event) || (drag->type != WM_DRAG_ASSET)) { | |||||
| return false; | |||||
| } | |||||
| return true; | |||||
| } | |||||
Severin: The distinction here isn't if something is an asset or not, but if something is an external… | |||||
Done Inline ActionsWould suggest view3d_ob_drop_poll_local_id(), since not every ID is an asset. This will also be the version executed when dragging from the Outliner, which of course isn't asset specific at all. Just note in a comment that this local ID may also be an asset. Severin: Would suggest `view3d_ob_drop_poll_local_id()`, since not every ID is an asset. This will also… | |||||
Done Inline ActionsRenamed to local_id to avoid too many iterations on this patch, I'm concerned this would be confused with local-id / linked-id terminology which is used throughout the code-base. While non_external_asset reads awkwardly, at least it's clear whats happening. campbellbarton: Renamed to `local_id` to avoid too many iterations on this patch, I'm concerned this would be… | |||||
Not Done Inline Actions
I'd argue against that. non_external_asset to me means an asset that isn't external, so local. However this is also used for IDs that are not marked as assets. Severin: > While `non_external_asset` reads awkwardly, at least it's clear whats happening.
I'd argue… | |||||
| /** | |||||
| * \note the term local here refers to not being an external asset, | |||||
Done Inline ActionsTogether with the suggested naming change, I'd change this to check drag->type != WM_DRAG_ID. Severin: Together with the suggested naming change, I'd change this to check `drag->type != WM_DRAG_ID`. | |||||
| * poll will succeed for linked library objects. | |||||
| */ | |||||
| static bool view3d_ob_drop_poll_local_id(bContext *C, wmDrag *drag, const wmEvent *event) | |||||
| { | |||||
| if (!view3d_ob_drop_poll(C, drag, event) || (drag->type != WM_DRAG_ID)) { | |||||
| return false; | |||||
| } | |||||
| return true; | |||||
| } | |||||
| static bool view3d_collection_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event) | static bool view3d_collection_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event) | ||||
| { | { | ||||
| return view3d_drop_id_in_main_region_poll(C, drag, event, ID_GR); | return view3d_drop_id_in_main_region_poll(C, drag, event, ID_GR); | ||||
| } | } | ||||
| static bool view3d_mat_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event) | static bool view3d_mat_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | |||||
| static bool view3d_volume_drop_poll(bContext *UNUSED(C), | static bool view3d_volume_drop_poll(bContext *UNUSED(C), | ||||
| wmDrag *drag, | wmDrag *drag, | ||||
| const wmEvent *UNUSED(event)) | const wmEvent *UNUSED(event)) | ||||
| { | { | ||||
| return (drag->type == WM_DRAG_PATH) && (drag->icon == ICON_FILE_VOLUME); | return (drag->type == WM_DRAG_PATH) && (drag->icon == ICON_FILE_VOLUME); | ||||
| } | } | ||||
| static void view3d_ob_drop_copy(wmDrag *drag, wmDropBox *drop) | static void view3d_ob_drop_copy_local_id(wmDrag *drag, wmDropBox *drop) | ||||
Not Done Inline Actionsview3d_ob_drop_copy_local_id()? Severin: `view3d_ob_drop_copy_local_id()`? | |||||
| { | { | ||||
| ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, ID_OB); | BLI_assert(drag->type != WM_DRAG_ASSET); | ||||
| ID *id = WM_drag_get_local_ID(drag, ID_OB); | |||||
| RNA_string_set(drop->ptr, "name", id->name + 2); | RNA_string_set(drop->ptr, "name", id->name + 2); | ||||
| /* Don't duplicate ID's which were just imported. Only do that for existing, local IDs. */ | } | ||||
| const bool is_imported_id = drag->type == WM_DRAG_ASSET; | |||||
| RNA_boolean_set(drop->ptr, "duplicate", !is_imported_id); | static void view3d_ob_drop_copy_external_asset(wmDrag *drag, wmDropBox *drop) | ||||
| { | |||||
| /* NOTE(@campbellbarton): Selection is handled here, de-selecting objects before append, | |||||
| * using auto-select to ensure the new objects are selected. | |||||
| * This is done so #OBJECT_OT_transform_to_mouse (which runs after this drop handler) | |||||
| * can use the context setup here to place the objects. */ | |||||
| BLI_assert(drag->type == WM_DRAG_ASSET); | |||||
| wmDragAsset *asset_drag = WM_drag_get_asset_data(drag, 0); | |||||
| bContext *C = asset_drag->evil_C; | |||||
| Scene *scene = CTX_data_scene(C); | |||||
| ViewLayer *view_layer = CTX_data_view_layer(C); | |||||
| BKE_view_layer_base_deselect_all(view_layer); | |||||
| ID *id = WM_drag_asset_id_import(asset_drag, FILE_AUTOSELECT); | |||||
| RNA_string_set(drop->ptr, "name", id->name + 2); | |||||
| Base *base = BKE_view_layer_base_find(view_layer, (Object *)id); | |||||
| if (base != NULL) { | |||||
| BKE_view_layer_base_select_and_set_active(view_layer, base); | |||||
| WM_main_add_notifier(NC_SCENE | ND_OB_ACTIVE, scene); | |||||
| } | |||||
| DEG_id_tag_update(&scene->id, ID_RECALC_SELECT); | |||||
| ED_outliner_select_sync_from_object_tag(C); | |||||
| } | } | ||||
| static void view3d_collection_drop_copy(wmDrag *drag, wmDropBox *drop) | static void view3d_collection_drop_copy(wmDrag *drag, wmDropBox *drop) | ||||
| { | { | ||||
| ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, ID_GR); | ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, ID_GR); | ||||
| RNA_string_set(drop->ptr, "name", id->name + 2); | RNA_string_set(drop->ptr, "name", id->name + 2); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | static void view3d_lightcache_update(bContext *C) | ||||
| WM_operator_properties_free(&op_ptr); | WM_operator_properties_free(&op_ptr); | ||||
| } | } | ||||
| /* region dropbox definition */ | /* region dropbox definition */ | ||||
| static void view3d_dropboxes(void) | static void view3d_dropboxes(void) | ||||
| { | { | ||||
| ListBase *lb = WM_dropboxmap_find("View3D", SPACE_VIEW3D, RGN_TYPE_WINDOW); | ListBase *lb = WM_dropboxmap_find("View3D", SPACE_VIEW3D, RGN_TYPE_WINDOW); | ||||
| /* Assets have separate logic. */ | |||||
| WM_dropbox_add(lb, | WM_dropbox_add(lb, | ||||
| "OBJECT_OT_add_named", | "OBJECT_OT_add_named", | ||||
| view3d_ob_drop_poll, | view3d_ob_drop_poll_local_id, | ||||
| view3d_ob_drop_copy, | view3d_ob_drop_copy_local_id, | ||||
| WM_drag_free_imported_drag_ID, | |||||
| NULL); | |||||
| WM_dropbox_add(lb, | |||||
| "OBJECT_OT_transform_to_mouse", | |||||
| view3d_ob_drop_poll_external_asset, | |||||
| view3d_ob_drop_copy_external_asset, | |||||
| WM_drag_free_imported_drag_ID, | WM_drag_free_imported_drag_ID, | ||||
| NULL); | NULL); | ||||
| WM_dropbox_add(lb, | WM_dropbox_add(lb, | ||||
| "OBJECT_OT_drop_named_material", | "OBJECT_OT_drop_named_material", | ||||
| view3d_mat_drop_poll, | view3d_mat_drop_poll, | ||||
| view3d_id_drop_copy, | view3d_id_drop_copy, | ||||
| WM_drag_free_imported_drag_ID, | WM_drag_free_imported_drag_ID, | ||||
| view3d_mat_drop_tooltip); | view3d_mat_drop_tooltip); | ||||
| ▲ Show 20 Lines • Show All 1,095 Lines • Show Last 20 Lines | |||||
The distinction here isn't if something is an asset or not, but if something is an external asset that has to be imported first, or a local ID, which may well be marked as asset too.
In hindsight, I find WM_DRAG_ASSET to be named badly, and reusing WM_DRAG_ID for local ID asset makes things even more confusing. Instead there should be WM_DRAG_ASSET_EXTERNAL and WM_DRAG_ASSET_LOCAL_ID or similar, but that's a separate cleanup.