fix [#33442] Units
[blender.git] / source / blender / windowmanager / intern / wm_operators.c
index c555f771a48d406a503e4e945bc7398d6061c041..8a0701b1063f523df96c474a9b16d49c2be64153 100644 (file)
@@ -87,6 +87,7 @@
 #include "ED_screen.h"
 #include "ED_util.h"
 #include "ED_object.h"
+#include "ED_view3d.h"
 
 #include "RNA_access.h"
 #include "RNA_define.h"
@@ -689,6 +690,35 @@ void WM_operator_properties_free(PointerRNA *ptr)
 
 /* ************ default op callbacks, exported *********** */
 
+int WM_operator_view3d_distance_invoke(struct bContext *C, struct wmOperator *op, struct wmEvent *UNUSED(event))
+{
+       Scene *scene = CTX_data_scene(C);
+       View3D *v3d = CTX_wm_view3d(C);
+
+       const float dia = v3d ? ED_view3d_grid_scale(scene, v3d, NULL) : ED_scene_grid_scale(scene, NULL);
+
+       /* always run, so the values are initialized,
+        * otherwise we may get differ behavior when (dia != 1.0) */
+       RNA_STRUCT_BEGIN(op->ptr, prop)
+       {
+               if (RNA_property_type(prop) == PROP_FLOAT) {
+                       PropertySubType pstype = RNA_property_subtype(prop);
+                       if (pstype == PROP_DISTANCE) {
+                               /* we don't support arrays yet */
+                               BLI_assert(RNA_property_array_check(prop) == FALSE);
+                               /* initialize */
+                               if (!RNA_property_is_set_ex(op->ptr, prop, FALSE)) {
+                                       const float value = RNA_property_float_get_default(op->ptr, prop) * dia;
+                                       RNA_property_float_set(op->ptr, prop, value);
+                               }
+                       }
+               }
+       }
+       RNA_STRUCT_END;
+
+       return op->type->exec(C, op);
+}
+
 /* invoke callback, uses enum property named "type" */
 int WM_menu_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
 {