[Bf-blender-cvs] [2d21eb79ad4] blender2.8: Units: Support for fixed units

Jacques Lucke noreply at git.blender.org
Wed Oct 3 10:22:06 CEST 2018


Commit: 2d21eb79ad48485bc7b3385d6df5c2c25fd88ee0
Author: Jacques Lucke
Date:   Wed Oct 3 10:20:16 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB2d21eb79ad48485bc7b3385d6df5c2c25fd88ee0

Units: Support for fixed units

Users can select the main unit they want to use now.
Previously the displayed unit always depended on the magnitude of the value.
The old behavior can be restored by switching to the "Adaptive" mode for length, mass and time units.

Meters, kilograms and seconds are the default units for new and old scenes.

The selected unit is also the default unit for user input.
E.g. if cm is selected, whenever the user inputs a unitless number into a field of type length, it will be interpreted as cm.

Reviewer: brecht

Differential: https://developer.blender.org/D3740

===================================================================

D	release/scripts/presets/units_length/centimeters.py
D	release/scripts/presets/units_length/feet.py
D	release/scripts/presets/units_length/inches.py
D	release/scripts/presets/units_length/kilometers.py
D	release/scripts/presets/units_length/meters.py
D	release/scripts/presets/units_length/miles.py
D	release/scripts/presets/units_length/millimeters.py
M	release/scripts/startup/bl_operators/presets.py
M	release/scripts/startup/bl_ui/properties_scene.py
M	source/blender/blenkernel/BKE_unit.h
M	source/blender/blenkernel/intern/scene.c
M	source/blender/blenkernel/intern/unit.c
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/draw/modes/edit_mesh_mode_text.c
M	source/blender/editors/include/ED_numinput.h
M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_eyedropper_depth.c
M	source/blender/editors/space_view3d/view3d_gizmo_ruler.c
M	source/blender/editors/space_view3d/view3d_ruler.c
M	source/blender/editors/transform/transform.c
M	source/blender/editors/util/numinput.c
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_scene.c

===================================================================

diff --git a/release/scripts/presets/units_length/centimeters.py b/release/scripts/presets/units_length/centimeters.py
deleted file mode 100644
index 80d5c3e8890..00000000000
--- a/release/scripts/presets/units_length/centimeters.py
+++ /dev/null
@@ -1,5 +0,0 @@
-import bpy
-scene = bpy.context.scene
-
-scene.unit_settings.system = 'METRIC'
-scene.unit_settings.scale_length = 0.01
diff --git a/release/scripts/presets/units_length/feet.py b/release/scripts/presets/units_length/feet.py
deleted file mode 100644
index 015cb810c4d..00000000000
--- a/release/scripts/presets/units_length/feet.py
+++ /dev/null
@@ -1,5 +0,0 @@
-import bpy
-scene = bpy.context.scene
-
-scene.unit_settings.system = 'IMPERIAL'
-scene.unit_settings.scale_length = 0.3048
diff --git a/release/scripts/presets/units_length/inches.py b/release/scripts/presets/units_length/inches.py
deleted file mode 100644
index 7bdc96329ec..00000000000
--- a/release/scripts/presets/units_length/inches.py
+++ /dev/null
@@ -1,5 +0,0 @@
-import bpy
-scene = bpy.context.scene
-
-scene.unit_settings.system = 'IMPERIAL'
-scene.unit_settings.scale_length = 0.0254
diff --git a/release/scripts/presets/units_length/kilometers.py b/release/scripts/presets/units_length/kilometers.py
deleted file mode 100644
index d2a80e56aaa..00000000000
--- a/release/scripts/presets/units_length/kilometers.py
+++ /dev/null
@@ -1,5 +0,0 @@
-import bpy
-scene = bpy.context.scene
-
-scene.unit_settings.system = 'METRIC'
-scene.unit_settings.scale_length = 1000.0
diff --git a/release/scripts/presets/units_length/meters.py b/release/scripts/presets/units_length/meters.py
deleted file mode 100644
index 831f1f26071..00000000000
--- a/release/scripts/presets/units_length/meters.py
+++ /dev/null
@@ -1,5 +0,0 @@
-import bpy
-scene = bpy.context.scene
-
-scene.unit_settings.system = 'METRIC'
-scene.unit_settings.scale_length = 1.0
diff --git a/release/scripts/presets/units_length/miles.py b/release/scripts/presets/units_length/miles.py
deleted file mode 100644
index 59c1e2b36a9..00000000000
--- a/release/scripts/presets/units_length/miles.py
+++ /dev/null
@@ -1,5 +0,0 @@
-import bpy
-scene = bpy.context.scene
-
-scene.unit_settings.system = 'IMPERIAL'
-scene.unit_settings.scale_length = 1609.344
diff --git a/release/scripts/presets/units_length/millimeters.py b/release/scripts/presets/units_length/millimeters.py
deleted file mode 100644
index b89918f8b1b..00000000000
--- a/release/scripts/presets/units_length/millimeters.py
+++ /dev/null
@@ -1,5 +0,0 @@
-import bpy
-scene = bpy.context.scene
-
-scene.unit_settings.system = 'METRIC'
-scene.unit_settings.scale_length = 0.001
diff --git a/release/scripts/startup/bl_operators/presets.py b/release/scripts/startup/bl_operators/presets.py
index 5dae38a129f..9cc1591494a 100644
--- a/release/scripts/startup/bl_operators/presets.py
+++ b/release/scripts/startup/bl_operators/presets.py
@@ -652,24 +652,6 @@ class WM_MT_operator_presets(Menu):
     preset_operator = "script.execute_preset"
 
 
-class AddPresetUnitsLength(AddPresetBase, Operator):
-    """Add or remove length units preset"""
-    bl_idname = "scene.units_length_preset_add"
-    bl_label = "Add Length Units Preset"
-    preset_menu = "SCENE_PT_units_length_presets"
-
-    preset_defines = [
-        "scene = bpy.context.scene"
-    ]
-
-    preset_values = [
-        "scene.unit_settings.system",
-        "scene.unit_settings.scale_length",
-    ]
-
-    preset_subdir = "units_length"
-
-
 class AddPresetGpencilBrush(AddPresetBase, Operator):
     """Add or remove grease pencil brush preset"""
     bl_idname = "scene.gpencil_brush_preset_add"
@@ -764,7 +746,6 @@ classes = (
     AddPresetTrackingCamera,
     AddPresetTrackingSettings,
     AddPresetTrackingTrackColor,
-    AddPresetUnitsLength,
     AddPresetGpencilBrush,
     AddPresetGpencilMaterial,
     ExecutePreset,
diff --git a/release/scripts/startup/bl_ui/properties_scene.py b/release/scripts/startup/bl_ui/properties_scene.py
index 8e3bfd63726..2cabefe905e 100644
--- a/release/scripts/startup/bl_ui/properties_scene.py
+++ b/release/scripts/startup/bl_ui/properties_scene.py
@@ -33,14 +33,6 @@ from .properties_physics_common import (
 )
 
 
-class SCENE_PT_units_length_presets(PresetMenu):
-    """Unit of measure for properties that use length values"""
-    bl_label = "Unit Presets"
-    preset_subdir = "units_length"
-    preset_operator = "script.execute_preset"
-    preset_add_operator = "scene.units_length_preset_add"
-
-
 class SCENE_UL_keying_set_paths(UIList):
     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
         # assert(isinstance(item, bpy.types.KeyingSetPath)
@@ -84,9 +76,6 @@ class SCENE_PT_unit(SceneButtonsPanel, Panel):
     bl_label = "Units"
     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_OPENGL'}
 
-    def draw_header_preset(self, context):
-        SCENE_PT_units_length_presets.draw_panel_header(self.layout)
-
     def draw(self, context):
         layout = self.layout
 
@@ -95,17 +84,21 @@ class SCENE_PT_unit(SceneButtonsPanel, Panel):
         layout.use_property_split = True
         layout.use_property_decorate = False
 
-        flow = layout.grid_flow(row_major=True, columns=0, even_columns=False, even_rows=False, align=True)
-
-        col = flow.column()
-        col.prop(unit, "system")
-        col.prop(unit, "system_rotation")
+        layout.prop(unit, "system")
 
-        col = flow.column()
+        col = layout.column()
         col.enabled = unit.system != 'NONE'
         col.prop(unit, "scale_length")
         col.prop(unit, "use_separate")
 
+        col = layout.column()
+        col.prop(unit, "system_rotation", text="Rotation")
+        subcol = col.column()
+        subcol.enabled = unit.system != 'NONE'
+        subcol.prop(unit, "length_unit", text="Length")
+        subcol.prop(unit, "mass_unit", text="Mass")
+        subcol.prop(unit, "time_unit", text="Time")
+
 
 class SceneKeyingSetsPanel:
 
@@ -607,7 +600,6 @@ class SCENE_PT_custom_props(SceneButtonsPanel, PropertyPanel, Panel):
 
 
 classes = (
-    SCENE_PT_units_length_presets,
     SCENE_UL_keying_set_paths,
     SCENE_PT_scene,
     SCENE_PT_unit,
diff --git a/source/blender/blenkernel/BKE_unit.h b/source/blender/blenkernel/BKE_unit.h
index 82a4659eec7..bb7fb006038 100644
--- a/source/blender/blenkernel/BKE_unit.h
+++ b/source/blender/blenkernel/BKE_unit.h
@@ -31,14 +31,23 @@
 extern "C" {
 #endif
 
+struct UnitSettings;
+
 /* in all cases the value is assumed to be scaled by the user preference */
 
 /* humanly readable representation of a value in units (used for button drawing) */
-size_t  bUnit_AsString(char *str, int len_max, double value, int prec, int system, int type, bool split, bool pad);
+size_t bUnit_AsString(char *str, int len_max, double value, int prec, int system, int type, bool split, bool pad);
+size_t bUnit_AsString2(char *str, int len_max, double value, int prec, int type, const struct UnitSettings *settings, bool pad);
 
 /* replace units with values, used before python button evaluation */
 bool bUnit_ReplaceString(char *str, int len_max, const char *str_prev, double scale_pref, int system, int type);
 
+/* return true if the string contains any valid unit for the given type */
+bool bUnit_ContainsUnit(const char *str, int system, int type);
+
+/* if user does not specify a unit, multiply with this value */
+double bUnit_PreferredUnitScalar(const struct UnitSettings *settings, int type);
+
 /* make string keyboard-friendly: 10µm --> 10um */
 void bUnit_ToUnitAltName(char *str, int len_max, const char *orig_str, int system, int type);
 
@@ -56,9 +65,11 @@ bool bUnit_IsValid(int system, int type);
 
 void        bUnit_GetSystem(int system, int type, void const **r_usys_pt, int *r_len);
 int         bUnit_GetBaseUnit(const void *usys_pt);
+int         bUnit_GetBaseUnitOfType(int system, int type);
 const char *bUnit_GetName(const void *usys_pt, int index);
 const char *bUnit_GetNameDisplay(const void *usys_pt, int index);
 double      bUnit_GetScaler(const void *usys_pt, int index);
+bool        bUnit_IsSuppressed(const void *usys_pt, int index);
 
 /* aligned with PropertyUnit */
 enum {
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 8c2f226eb8b..44406714771 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -703,6 +703,9 @@ void BKE_scene_init(Scene *sce)
 
 	sce->unit.system = USER_UNIT_METRIC;
 	sce->unit.scale_length = 1.0f;
+	sce->unit.length_unit = bUnit_GetBaseUnitOfType(USER_UNIT_METRIC, B_UNIT_LENGTH);
+	sce->unit.mass_unit = bUnit_GetBaseUnitOfType(USER_UNIT_METRIC, B_UNIT_MASS);
+	sce->unit.time_unit = bUnit_GetBaseUnitOfType(USER_UNIT_METRIC, B_UNIT_TIME);
 
 	pset = &sce->toolsettings->particle;
 	pset->flag = PE_KEEP_LENGTHS | PE_LOCK_FIRST | PE_DEFLECT_EMITTER | PE_AUTO_VELOCITY;
diff --git a/source/blender/blenkernel/intern/unit.c b/source/blender/blenkernel/intern/unit.c
index 3a903eb31c1..c132053a82b 100644
--- a/source/blender/blenkernel/intern/unit.c
+++ b/source/blender/blenkernel/intern/unit.c
@@ -35,6 +35,8 @@
 #include "BLI_string.h"
 #include "BLI_string_utf8.h"
 
+#include "DNA_scene_types.h"
+
 #include "BKE_unit.h"  /* own include */
 
 #ifdef WIN32
@@ -108,6 +110,8 @@ typedef struct bUnitCollection {
 	int length; /* to quickly find the last item */
 } bUnitCollection;
 
+#define UNIT_COLLECTION_LENGTH(def) (sizeof(def) / sizeof(bUnitDef) - 1)
+
 /* Dummy */
 static struct bUnitDef buDummyDef[] = { {"", NULL, "", NULL, NULL, 1.0, 0.0}, {NULL, NULL, NULL, NULL, NULL, 0.0, 0.0}};
 static struct bUnitCollection buDummyCollection = {buDummyDef, 0, 0, sizeof(buDummyDef)};
@@ -121,7 +125,7 @@ static const struct bUnitDef buMetricLenDef[] = {
 	{"decimeter", "decimeters",     "dm",  NULL, "10 Centimeters", UN_SC_DM, 0.0, B_UNIT_DEF_SUPPRESS},
 	{"centimeter", "centimeters",   "cm",  NULL, "Centimeters", UN_SC_CM, 0.0,    B_UNIT_DEF_NONE},
 	{"millimeter", "millimeters",   "mm",  NULL, "Millimeters", UN_SC_MM, 0.0,    B_UNIT_DEF_NONE | B_UNIT_DEF_TENTH},
-	{"micrometer", "micrometers",   "µm",  "um", "Micrometers", UN_SC_UM,  0.0, B_UNIT_DEF_NONE},
+

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list