Transform: Implement Snap to Grid mode #116109

Merged
Germano Cavalcante merged 4 commits from mano-wii/blender:snap_to_grid into main 2024-03-27 13:17:37 +01:00
8 changed files with 43 additions and 21 deletions
Showing only changes of commit 9710a002a7 - Show all commits

View File

@ -2251,8 +2251,11 @@ class USERPREF_PT_addons(AddOnPanel, Panel):
prefs = context.preferences
use_extension_repos = prefs.experimental.use_extension_repos
if use_extension_repos and self.is_extended():
if (
prefs.view.show_developer_ui and
prefs.experimental.use_extension_repos and
self.is_extended()
):
# Rely on the draw function being appended to by the extensions add-on.
return

View File

@ -110,6 +110,7 @@ enum eCbEvent {
BKE_CB_EVT_EXTENSION_REPOS_UPDATE_POST,
BKE_CB_EVT_EXTENSION_REPOS_SYNC,
BKE_CB_EVT_EXTENSION_REPOS_UPGRADE,
BKE_CB_EVT_EXTENSION_REPOS_FILES_CLEAR,
BKE_CB_EVT_TOT,
};

View File

@ -1224,7 +1224,7 @@ void ED_view3d_grid_steps(const Scene *scene,
* The actual code is seen in `object_grid_frag.glsl` (see `grid_res`).
* Currently the simulation is only done when RV3D_VIEW_IS_AXIS.
*/
float ED_view3d_grid_view_scale(Scene *scene,
float ED_view3d_grid_view_scale(const Scene *scene,
const View3D *v3d,
const ARegion *region,
const char **r_grid_unit);
@ -1287,8 +1287,8 @@ void ED_view3d_draw_bgpic_test(const Scene *scene,
/* view3d_gizmo_preselect_type.cc */
void ED_view3d_gizmo_mesh_preselect_get_active(bContext *C,
wmGizmo *gz,
void ED_view3d_gizmo_mesh_preselect_get_active(const bContext *C,
const wmGizmo *gz,
Base **r_base,
BMElem **r_ele);
void ED_view3d_gizmo_mesh_preselect_clear(wmGizmo *gz);
@ -1305,8 +1305,8 @@ void ED_view3d_buttons_region_layout_ex(const bContext *C,
* See if current UUID is valid, otherwise set a valid UUID to v3d,
* Try to keep the same UUID previously used to allow users to quickly toggle back and forth.
*/
bool ED_view3d_local_collections_set(Main *bmain, View3D *v3d);
void ED_view3d_local_collections_reset(bContext *C, bool reset_all);
bool ED_view3d_local_collections_set(const Main *bmain, View3D *v3d);
void ED_view3d_local_collections_reset(const bContext *C, bool reset_all);
#ifdef WITH_XR_OPENXR
void ED_view3d_xr_mirror_update(const ScrArea *area, const View3D *v3d, bool enable);

View File

@ -578,10 +578,26 @@ static int preferences_extension_repo_remove_exec(bContext *C, wmOperator *op)
char dirpath[FILE_MAX];
BKE_preferences_extension_repo_dirpath_get(repo, dirpath, sizeof(dirpath));
if (dirpath[0] && BLI_is_dir(dirpath)) {
if (BLI_delete(dirpath, true, true) != 0) {
/* Removing custom directories has the potential to remove user data
* if users accidentally point this to their home directory or similar.
* Even though the UI shows a warning, we better prevent any accidents
* caused by recursive removal, see #119481.
* Only check custom directories because the non-custom directory is always
* a specific location under Blender's local extensions directory. */
const bool recursive = (repo->flag & USER_EXTENSION_REPO_FLAG_USE_CUSTOM_DIRECTORY) == 0;
/* Perform package manager specific clear operations,
* needed when `recursive` is false so the empty directory can be removed.
* If it's not empty there will be a warning that the directory couldn't be removed.
* The user will have to do this manually which is good since unknown files
* could be user data. */
BKE_callback_exec_string(bmain, BKE_CB_EVT_EXTENSION_REPOS_FILES_CLEAR, dirpath);
if (BLI_delete(dirpath, true, recursive) != 0) {
BKE_reportf(op->reports,
RPT_ERROR,
"Error removing directory: %s",
RPT_WARNING,
"Unable to remove directory: %s",
errno ? strerror(errno) : "unknown");
}
}
@ -688,9 +704,7 @@ static void PREFERENCES_OT_extension_repo_upgrade(wmOperatorType *ot)
/** \name Drop Extension Operator
* \{ */
static int preferences_extension_url_drop_invoke(bContext *C,
wmOperator *op,
const wmEvent * /*event*/)
static int preferences_extension_url_drop_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
char *url = RNA_string_get_alloc(op->ptr, "url", nullptr, 0, nullptr);
const bool url_is_remote = STRPREFIX(url, "http://") || STRPREFIX(url, "https://") ||
@ -705,7 +719,7 @@ static int preferences_extension_url_drop_invoke(bContext *C,
PointerRNA props_ptr;
WM_operator_properties_create_ptr(&props_ptr, ot);
RNA_string_set(&props_ptr, "url", url);
WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &props_ptr, nullptr);
WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &props_ptr, event);
WM_operator_properties_free(&props_ptr);
retval = OPERATOR_FINISHED;
}

View File

@ -914,7 +914,7 @@ void ED_view3d_grid_steps(const Scene *scene,
view3d_grid_steps_ex(scene, v3d, rv3d, r_grid_steps, nullptr, nullptr);
}
float ED_view3d_grid_view_scale(Scene *scene,
float ED_view3d_grid_view_scale(const Scene *scene,
const View3D *v3d,
const ARegion *region,
const char **r_grid_unit)

View File

@ -493,8 +493,8 @@ void ED_gizmotypes_preselect_3d()
* the information from this gizmo.
* \{ */
void ED_view3d_gizmo_mesh_preselect_get_active(bContext *C,
wmGizmo *gz,
void ED_view3d_gizmo_mesh_preselect_get_active(const bContext *C,
const wmGizmo *gz,
Base **r_base,
BMElem **r_ele)
{

View File

@ -1147,7 +1147,9 @@ void VIEW3D_OT_localview_remove_from(wmOperatorType *ot)
/** \name Local Collections
* \{ */
static uint free_localcollection_bit(Main *bmain, ushort local_collections_uid, bool *r_reset)
static uint free_localcollection_bit(const Main *bmain,
ushort local_collections_uid,
bool *r_reset)
{
ushort local_view_bits = 0;
@ -1196,7 +1198,7 @@ static void local_collections_reset_uuid(LayerCollection *layer_collection,
}
}
static void view3d_local_collections_reset(Main *bmain, const uint local_view_bit)
static void view3d_local_collections_reset(const Main *bmain, const uint local_view_bit)
{
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
@ -1207,7 +1209,7 @@ static void view3d_local_collections_reset(Main *bmain, const uint local_view_bi
}
}
bool ED_view3d_local_collections_set(Main *bmain, View3D *v3d)
bool ED_view3d_local_collections_set(const Main *bmain, View3D *v3d)
{
if ((v3d->flag & V3D_LOCAL_COLLECTIONS) == 0) {
return true;
@ -1231,7 +1233,7 @@ bool ED_view3d_local_collections_set(Main *bmain, View3D *v3d)
return true;
}
void ED_view3d_local_collections_reset(bContext *C, const bool reset_all)
void ED_view3d_local_collections_reset(const bContext *C, const bool reset_all)
{
Main *bmain = CTX_data_main(C);
uint local_view_bit = ~(0);

View File

@ -96,6 +96,8 @@ static PyStructSequence_Field app_cb_info_fields[] = {
{"_extension_repos_update_post", "on changes to extension repos (after)"},
{"_extension_repos_sync", "on creating or synchronizing the active repository"},
{"_extension_repos_upgrade", "on upgrading the active repository"},
{"_extension_repos_files_clear",
"remove files from the repository directory (uses as a string argument)"},
/* sets the permanent tag */
#define APP_CB_OTHER_FIELDS 1