Files
test2/source/blender/editors/space_view3d/view3d_header.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

166 lines
4.8 KiB
C++
Raw Normal View History

/* SPDX-FileCopyrightText: 2004-2008 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup spview3d
2011-02-27 20:29:51 +00:00
*/
#include <cstdlib>
#include <cstring>
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "BLI_utildefines.h"
#include "BKE_context.hh"
#include "BKE_editmesh.hh"
2024-01-23 15:18:09 -05:00
#include "BKE_layer.hh"
Fix #44834: Add bone selection icon next to face and vertex selection in weight paint mode Currently, in weight paint mode, there is an icon for face and vertex selection mode, but there isn't one for the default mode where the user can select a bone in any tool by alt clicking. This lack of indication might lead to confusion for the users when they are not able to select a bone by alt clicking during weight painting. By adding a bone selection icon when there is a pose mode armature, we can communicate to the user that: 1. they can select a bone while the bone selection icon is active. (when they are not in face or vertex selection mode) 2. they have forgot to select an armature when entering weight paint mode by not showing the bone selection icon at all when there is no pose mode armature. When the bone selection icon is inactive, the user can't select a bone. (alt clicking selects face and vertex mode's respective element) When no armature is selected when entering weight paint mode, the bone selection icon doesn't show up indicating that the user has forgot to select an armature. (The user is also unable to select a bone by alt clicking.) ## Selection tool for bone selection mode Currently, while selection tools exist for face and vertex selection mode, one doesn't exist for the default mode (bone selection mode). As the default mode will be getting a clear indicator that it will function as a bone selection mode, I added a selection tool entry for the bone selection mode. Face and vertex selection modes has the shortcut 1 and 2, so it seemed natural to give bone selection mode the shortcut of 3. Pull Request: https://projects.blender.org/blender/blender/pulls/115409
2023-12-01 13:38:58 +01:00
#include "BKE_object.hh"
#include "DEG_depsgraph.hh"
#include "RNA_access.hh"
#include "RNA_prototypes.hh"
2013-03-07 02:44:55 +00:00
#include "WM_api.hh"
#include "WM_types.hh"
2013-03-07 02:44:55 +00:00
#include "UI_interface.hh"
#include "UI_resources.hh"
#include "view3d_intern.hh"
/* -------------------------------------------------------------------- */
/** \name Toggle Matcap Flip Operator
* \{ */
static int toggle_matcap_flip_exec(bContext *C, wmOperator * /*op*/)
{
View3D *v3d = CTX_wm_view3d(C);
if (v3d) {
v3d->shading.flag ^= V3D_SHADING_MATCAP_FLIP_X;
ED_view3d_shade_update(CTX_data_main(C), v3d, CTX_wm_area(C));
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
}
else {
Scene *scene = CTX_data_scene(C);
scene->display.shading.flag ^= V3D_SHADING_MATCAP_FLIP_X;
DEG_id_tag_update(&scene->id, ID_RECALC_SYNC_TO_EVAL);
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
}
return OPERATOR_FINISHED;
}
void VIEW3D_OT_toggle_matcap_flip(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Flip MatCap";
ot->description = "Flip MatCap";
ot->idname = "VIEW3D_OT_toggle_matcap_flip";
/* api callbacks */
ot->exec = toggle_matcap_flip_exec;
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name UI Templates
* \{ */
void uiTemplateEditModeSelection(uiLayout *layout, bContext *C)
{
Object *obedit = CTX_data_edit_object(C);
if (!obedit || obedit->type != OB_MESH) {
return;
}
BMEditMesh *em = BKE_editmesh_from_object(obedit);
uiLayout *row = uiLayoutRow(layout, true);
PointerRNA op_ptr;
wmOperatorType *ot = WM_operatortype_find("MESH_OT_select_mode", true);
uiItemFullO_ptr(row,
ot,
"",
ICON_VERTEXSEL,
nullptr,
WM_OP_INVOKE_DEFAULT,
(em->selectmode & SCE_SELECT_VERTEX) ? UI_ITEM_O_DEPRESS : UI_ITEM_NONE,
&op_ptr);
RNA_enum_set(&op_ptr, "type", SCE_SELECT_VERTEX);
uiItemFullO_ptr(row,
ot,
"",
ICON_EDGESEL,
nullptr,
WM_OP_INVOKE_DEFAULT,
(em->selectmode & SCE_SELECT_EDGE) ? UI_ITEM_O_DEPRESS : UI_ITEM_NONE,
&op_ptr);
RNA_enum_set(&op_ptr, "type", SCE_SELECT_EDGE);
uiItemFullO_ptr(row,
ot,
"",
ICON_FACESEL,
nullptr,
WM_OP_INVOKE_DEFAULT,
(em->selectmode & SCE_SELECT_FACE) ? UI_ITEM_O_DEPRESS : UI_ITEM_NONE,
&op_ptr);
RNA_enum_set(&op_ptr, "type", SCE_SELECT_FACE);
}
static void uiTemplatePaintModeSelection(uiLayout *layout, bContext *C)
{
ViewLayer: Lazy sync of scene data. When a change happens which invalidates view layers the syncing will be postponed until the first usage. This will improve importing or adding many objects in a single operation/script. `BKE_view_layer_need_resync_tag` is used to tag the view layer to be out of sync. Before accessing `BKE_view_layer_active_base_get`, `BKE_view_layer_active_object_get`, `BKE_view_layer_active_collection` or `BKE_view_layer_object_bases` the caller should call `BKE_view_layer_synced_ensure`. Having two functions ensures that partial syncing could be added as smaller patches in the future. Tagging a view layer out of sync could be replaced with a partial sync. Eventually the number of full resyncs could be reduced. After all tagging has been replaced with partial syncs the ensure_sync could be phased out. This patch has been added to discuss the details and consequences of the current approach. For clarity the call to BKE_view_layer_ensure_sync is placed close to the getters. In the future this could be placed in more strategical places to reduce the number of calls or improve performance. Finding those strategical places isn't that clear. When multiple operations are grouped in a single script you might want to always check for resync. Some areas found that can be improved. This list isn't complete. These areas aren't addressed by this patch as these changes would be hard to detect to the reviewer. The idea is to add changes to these areas as a separate patch. It might be that the initial commit would reduce performance compared to master, but will be fixed by the additional patches. **Object duplication** During object duplication the syncing is temporarily disabled. With this patch this isn't useful as when disabled the view_layer is accessed to locate bases. This can be improved by first locating the source bases, then duplicate and sync and locate the new bases. Will be solved in a separate patch for clarity reasons ({D15886}). **Object add** `BKE_object_add` not only adds a new object, but also selects and activates the new base. This requires the view_layer to be resynced. Some callers reverse the selection and activation (See `get_new_constraint_target`). We should make the selection and activation optional. This would make it possible to add multiple objects without having to resync per object. **Postpone Activate Base** Setting the basact is done in many locations. They follow a rule as after an action find the base and set the basact. Finding the base could require a resync. The idea is to store in the view_layer the object which base will be set in the basact during the next sync, reducing the times resyncing needs to happen. Reviewed By: mont29 Maniphest Tasks: T73411 Differential Revision: https://developer.blender.org/D15885
2022-09-14 21:33:51 +02:00
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
ViewLayer: Lazy sync of scene data. When a change happens which invalidates view layers the syncing will be postponed until the first usage. This will improve importing or adding many objects in a single operation/script. `BKE_view_layer_need_resync_tag` is used to tag the view layer to be out of sync. Before accessing `BKE_view_layer_active_base_get`, `BKE_view_layer_active_object_get`, `BKE_view_layer_active_collection` or `BKE_view_layer_object_bases` the caller should call `BKE_view_layer_synced_ensure`. Having two functions ensures that partial syncing could be added as smaller patches in the future. Tagging a view layer out of sync could be replaced with a partial sync. Eventually the number of full resyncs could be reduced. After all tagging has been replaced with partial syncs the ensure_sync could be phased out. This patch has been added to discuss the details and consequences of the current approach. For clarity the call to BKE_view_layer_ensure_sync is placed close to the getters. In the future this could be placed in more strategical places to reduce the number of calls or improve performance. Finding those strategical places isn't that clear. When multiple operations are grouped in a single script you might want to always check for resync. Some areas found that can be improved. This list isn't complete. These areas aren't addressed by this patch as these changes would be hard to detect to the reviewer. The idea is to add changes to these areas as a separate patch. It might be that the initial commit would reduce performance compared to master, but will be fixed by the additional patches. **Object duplication** During object duplication the syncing is temporarily disabled. With this patch this isn't useful as when disabled the view_layer is accessed to locate bases. This can be improved by first locating the source bases, then duplicate and sync and locate the new bases. Will be solved in a separate patch for clarity reasons ({D15886}). **Object add** `BKE_object_add` not only adds a new object, but also selects and activates the new base. This requires the view_layer to be resynced. Some callers reverse the selection and activation (See `get_new_constraint_target`). We should make the selection and activation optional. This would make it possible to add multiple objects without having to resync per object. **Postpone Activate Base** Setting the basact is done in many locations. They follow a rule as after an action find the base and set the basact. Finding the base could require a resync. The idea is to store in the view_layer the object which base will be set in the basact during the next sync, reducing the times resyncing needs to happen. Reviewed By: mont29 Maniphest Tasks: T73411 Differential Revision: https://developer.blender.org/D15885
2022-09-14 21:33:51 +02:00
BKE_view_layer_synced_ensure(scene, view_layer);
Object *ob = BKE_view_layer_active_object_get(view_layer);
/* Gizmos aren't used in paint modes */
if (!ELEM(ob->mode, OB_MODE_SCULPT, OB_MODE_PARTICLE_EDIT)) {
/* masks aren't used for sculpt and particle painting */
PointerRNA meshptr = RNA_pointer_create_discrete(
static_cast<ID *>(ob->data), &RNA_Mesh, ob->data);
2020-06-18 12:21:38 +10:00
if (ob->mode & OB_MODE_TEXTURE_PAINT) {
uiItemR(layout, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
}
else {
uiLayout *row = uiLayoutRow(layout, true);
uiItemR(row, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
uiItemR(row, &meshptr, "use_paint_mask_vertex", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
Fix #44834: Add bone selection icon next to face and vertex selection in weight paint mode Currently, in weight paint mode, there is an icon for face and vertex selection mode, but there isn't one for the default mode where the user can select a bone in any tool by alt clicking. This lack of indication might lead to confusion for the users when they are not able to select a bone by alt clicking during weight painting. By adding a bone selection icon when there is a pose mode armature, we can communicate to the user that: 1. they can select a bone while the bone selection icon is active. (when they are not in face or vertex selection mode) 2. they have forgot to select an armature when entering weight paint mode by not showing the bone selection icon at all when there is no pose mode armature. When the bone selection icon is inactive, the user can't select a bone. (alt clicking selects face and vertex mode's respective element) When no armature is selected when entering weight paint mode, the bone selection icon doesn't show up indicating that the user has forgot to select an armature. (The user is also unable to select a bone by alt clicking.) ## Selection tool for bone selection mode Currently, while selection tools exist for face and vertex selection mode, one doesn't exist for the default mode (bone selection mode). As the default mode will be getting a clear indicator that it will function as a bone selection mode, I added a selection tool entry for the bone selection mode. Face and vertex selection modes has the shortcut 1 and 2, so it seemed natural to give bone selection mode the shortcut of 3. Pull Request: https://projects.blender.org/blender/blender/pulls/115409
2023-12-01 13:38:58 +01:00
/* Show the bone selection mode icon only if there is a pose mode armature */
Object *ob_armature = BKE_object_pose_armature_get(ob);
if (ob_armature) {
uiItemR(row, &meshptr, "use_paint_bone_selection", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
}
}
}
}
void uiTemplateHeader3D_mode(uiLayout *layout, bContext *C)
{
ViewLayer: Lazy sync of scene data. When a change happens which invalidates view layers the syncing will be postponed until the first usage. This will improve importing or adding many objects in a single operation/script. `BKE_view_layer_need_resync_tag` is used to tag the view layer to be out of sync. Before accessing `BKE_view_layer_active_base_get`, `BKE_view_layer_active_object_get`, `BKE_view_layer_active_collection` or `BKE_view_layer_object_bases` the caller should call `BKE_view_layer_synced_ensure`. Having two functions ensures that partial syncing could be added as smaller patches in the future. Tagging a view layer out of sync could be replaced with a partial sync. Eventually the number of full resyncs could be reduced. After all tagging has been replaced with partial syncs the ensure_sync could be phased out. This patch has been added to discuss the details and consequences of the current approach. For clarity the call to BKE_view_layer_ensure_sync is placed close to the getters. In the future this could be placed in more strategical places to reduce the number of calls or improve performance. Finding those strategical places isn't that clear. When multiple operations are grouped in a single script you might want to always check for resync. Some areas found that can be improved. This list isn't complete. These areas aren't addressed by this patch as these changes would be hard to detect to the reviewer. The idea is to add changes to these areas as a separate patch. It might be that the initial commit would reduce performance compared to master, but will be fixed by the additional patches. **Object duplication** During object duplication the syncing is temporarily disabled. With this patch this isn't useful as when disabled the view_layer is accessed to locate bases. This can be improved by first locating the source bases, then duplicate and sync and locate the new bases. Will be solved in a separate patch for clarity reasons ({D15886}). **Object add** `BKE_object_add` not only adds a new object, but also selects and activates the new base. This requires the view_layer to be resynced. Some callers reverse the selection and activation (See `get_new_constraint_target`). We should make the selection and activation optional. This would make it possible to add multiple objects without having to resync per object. **Postpone Activate Base** Setting the basact is done in many locations. They follow a rule as after an action find the base and set the basact. Finding the base could require a resync. The idea is to store in the view_layer the object which base will be set in the basact during the next sync, reducing the times resyncing needs to happen. Reviewed By: mont29 Maniphest Tasks: T73411 Differential Revision: https://developer.blender.org/D15885
2022-09-14 21:33:51 +02:00
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
ViewLayer: Lazy sync of scene data. When a change happens which invalidates view layers the syncing will be postponed until the first usage. This will improve importing or adding many objects in a single operation/script. `BKE_view_layer_need_resync_tag` is used to tag the view layer to be out of sync. Before accessing `BKE_view_layer_active_base_get`, `BKE_view_layer_active_object_get`, `BKE_view_layer_active_collection` or `BKE_view_layer_object_bases` the caller should call `BKE_view_layer_synced_ensure`. Having two functions ensures that partial syncing could be added as smaller patches in the future. Tagging a view layer out of sync could be replaced with a partial sync. Eventually the number of full resyncs could be reduced. After all tagging has been replaced with partial syncs the ensure_sync could be phased out. This patch has been added to discuss the details and consequences of the current approach. For clarity the call to BKE_view_layer_ensure_sync is placed close to the getters. In the future this could be placed in more strategical places to reduce the number of calls or improve performance. Finding those strategical places isn't that clear. When multiple operations are grouped in a single script you might want to always check for resync. Some areas found that can be improved. This list isn't complete. These areas aren't addressed by this patch as these changes would be hard to detect to the reviewer. The idea is to add changes to these areas as a separate patch. It might be that the initial commit would reduce performance compared to master, but will be fixed by the additional patches. **Object duplication** During object duplication the syncing is temporarily disabled. With this patch this isn't useful as when disabled the view_layer is accessed to locate bases. This can be improved by first locating the source bases, then duplicate and sync and locate the new bases. Will be solved in a separate patch for clarity reasons ({D15886}). **Object add** `BKE_object_add` not only adds a new object, but also selects and activates the new base. This requires the view_layer to be resynced. Some callers reverse the selection and activation (See `get_new_constraint_target`). We should make the selection and activation optional. This would make it possible to add multiple objects without having to resync per object. **Postpone Activate Base** Setting the basact is done in many locations. They follow a rule as after an action find the base and set the basact. Finding the base could require a resync. The idea is to store in the view_layer the object which base will be set in the basact during the next sync, reducing the times resyncing needs to happen. Reviewed By: mont29 Maniphest Tasks: T73411 Differential Revision: https://developer.blender.org/D15885
2022-09-14 21:33:51 +02:00
BKE_view_layer_synced_ensure(scene, view_layer);
Object *ob = BKE_view_layer_active_object_get(view_layer);
Object *obedit = CTX_data_edit_object(C);
bool is_paint = (ob && ELEM(ob->mode,
OB_MODE_SCULPT,
OB_MODE_VERTEX_PAINT,
OB_MODE_WEIGHT_PAINT,
OB_MODE_TEXTURE_PAINT));
uiTemplateEditModeSelection(layout, C);
if ((obedit == nullptr) && is_paint) {
uiTemplatePaintModeSelection(layout, C);
}
}
/** \} */