Commit Graph

100 Commits

Author SHA1 Message Date
9953eeb012 Cleanup: use const for units API
Also make return args explicit.
2016-05-03 13:52:07 +10:00
5704ba7f9b Cleanup: style, spelling 2016-03-09 19:34:26 +11:00
f51ef8ac4d Correction to own previous rB9c0de0084bfe.
'1mm+1m' would fail with original fix, now consuming all alpha chars before checking unit again...
2016-03-02 18:12:14 +01:00
9c0de0084b Fix T47661: cm (centimeter) unit breaks m (meter) unit in Metric.
`m` unit when used after `cm`/`mm`/etc. ones would get ignored, and the alt version of miles
would be used instead.

The root of the issue is that, in `unit_find_str`, once we get a 'hit' for a unit, we check
it's actual unit (since 'm' would also hit on 'cm', 'mm', etc.). In case that hit is not a
valid unit one, we would just return NULL, breaking the cycle of checks over that unit, and
hence missing all later usages of it.

So now, in case we have an 'invalid unit hit', we immediately retry to find it within remaining string.
2016-03-02 18:02:19 +01:00
ae8e4d3718 Cleanup: redundant 'break', minor edits 2015-11-19 22:52:13 +11:00
86aeb7df96 Fix T46379: Bad behavior of bUnit_ToUnitAltName() with default units.
It would simply remove default units (in most case), cannot see any good reason for such behavior?
Might work in case default unit is the only one present, but breaks consistency (and it may not be
always obvious for user which unit it is). Comes from original patch from five years ago, rB7d8f0fce.

This will break keyboard-setting of values, e.g. '2m 33.4cm' would become '2 33.4cm',
totally useless and invalid entry!
2015-10-05 12:02:02 +02:00
2fe9224375 Fix T45459: Edge Length with Separate Units Displayed As 1m 100cm.
Our 'unit epsilon' was too small, given the fact we only display up to four digits usually...
2015-07-16 17:45:51 +02:00
b7c42ef93e Cleanup: use ascii as suffix (as with utf8) 2015-07-14 09:17:00 +10:00
bf69453ae7 BLI_string: add BLI_snprintf_rlen
use when the length of the destination string is needed.
2015-04-22 05:37:22 +10:00
b198500c02 Move bUnit_getScaleUnit -> BKE_scene_unit_scale
unit.c intentionally doesn't include DNA or BKE headers (except its own)
2014-08-26 20:53:41 +10:00
0e3fa0b761 Fix T41590: When scene scale is not 1.0, and units are "None," Blender assumes translations are in meters.
Turned out there were several issues in handling of scale parameter by numinput.
Fixed that by factorizing more some code in common with 'usual' numbuttons eval code
(new `bUnit_getScaleUnit()` helper will return valid scaled value, depending on
given system and type).

Now, numinput behaves as expected - using default unit amended by scale in case no unit is given
(i.e. entering '20' with a scale of 0.01 will give you 20cm, and '20cm' as well!).
2014-08-26 12:31:08 +02:00
27e7760913 BKE_units: Some cleanup (mostly bools instead of ints). 2014-08-20 12:31:15 +02:00
8535b9bd15 Fix T38722: Adding units in Imperial setting results in inconsistent values
Now always check for a default unit, and evaluate the whole expression in this "unit space".
Not an ideal solution, but should handle most cases nicely
(we can't address all possible corner cases anyway).

Note default unit is searched in current string first (bigger unit of current system wins),
then in previous string.

Note this also replaces ',' by '+' in default separation between units,
helps solving issues with parenthesis (e.g. (1'1")*2.5 would fail in existing code)!
This would break if someone uses py ops with lower precedence than '+' (like bitwise
operations, and comparison), but these are not expected usecase here anyway.

Reviewers: campbellbarton

Differential Revision: https://developer.blender.org/D340
2014-08-20 12:12:03 +02:00
5e3e095e2e Code Cleanup: use const 2014-07-12 09:09:24 +10:00
fa257adf96 Fix some loss of precision in BKE's unit code.
When converting text to value, units' "value" had only 6 digits of precision,
leading to annoying loss of precision esp. when mixing big and small units
(like e.g. miles and inches).
2014-06-17 16:06:12 +02:00
a2c107aef1 Code cleanup: use 'const' for arrays (blenkernel) 2014-04-27 00:25:15 +10:00
617557b08e Code cleanup: remove TRUE/FALSE & WITH_BOOL_COMPAT define 2014-04-01 15:22:28 +11:00
37026b12ec Code cleanup: use bool for static methods 2014-02-05 22:36:15 +11:00
d900f5be55 Code cleanup: use bools where possible 2014-02-03 19:35:44 +11:00
b9114cb609 UI: Use bool rather then int/short's where possible 2014-01-04 18:10:01 +11:00
e505203e8d Units: Add milligrams for mass
Avoids having small values displayed as "0kg".
2014-01-04 04:22:20 +01:00
4915706df6 Revert "Units: Make grams base unit for mass"
This reverts commit ead6d397fd.
2014-01-04 04:22:20 +01:00
ead6d397fd Units: Make grams base unit for mass 2013-12-31 18:10:30 +01:00
87cc890aef Support units in modal numinput
Summary:
This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value.

We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so).

Features:
- units (cm, ", deg, etc.).
- basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.).
- you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything.
- you can go to next/previous value with (ctrl-)TAB key.
- As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse.

Notes:
- Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent.
- Added back radian support in BKE_unit.
- Added arcminute/arcsecond to BKE_unit.
(those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units).

Related to T37600.

Reviewers: brecht, campbellbarton, carter2422

Reviewed By: brecht, campbellbarton, carter2422
Thanks everybody!

Differential Revision: http://developer.blender.org/D61
2013-12-21 17:44:48 +01:00
dde5e5ce25 User Interface: Align number buttons labels to the left, number right 2013-12-11 21:27:13 +11:00
63caaa2b12 Code Cleanup: rename vars for detecting change to be more consistent
rename change/is_change/is_changed/modified -> changed
also use bools over int/short/char and once accidental float.
2013-11-26 06:39:14 +11:00
1a0fed9ee0 More fix for this stupid uppercase-to-lowercase convertion code... Thanks to Lockal for noting this! 2013-11-16 15:34:47 +01:00
d27f8103dd Fix [#37393] Input dimensions are case sensitive in the property panel, uppercase input is misinterpreted
Typo in lowercasing code!
2013-11-10 19:51:44 +00:00
5ef717bec6 [#37327] Inconsistent numeric input conversion.
Issue was actually that micrometer was not drawing correctly (from r58165), reverted that fix and instead use utf8 drawing for editmode metrics when using a unit system (we already had a similar hack for surfaces and volumes, anyway).
2013-11-08 11:25:50 +00:00
991459d0ce fix [#36090] Blender displays strange symbol in edge length 2013-07-11 05:11:10 +00:00
46eb79c862 units: display 0.5mm rather then 500um, nicer when dealing with very small sizes but not microscopic. 2013-05-30 21:17:50 +00:00
2b2099cd51 Fix #34875: 0 digits of precision was not supported for FloatProperty, now
you can specify precision=0 for this, and use -1 for the default 2.
2013-04-08 18:55:08 +00:00
ffc8ecc587 use BLI_strncpy_rlen() rather then BLI_snprintf() when no formatting is needed.
also replace sprintf with strcpy when no formatting is done.
2013-03-14 10:39:18 +00:00
5162a155af Fix #34481: camera focal length and sensor size did not use units yet, now they do.
I've added a separate camera unit type. It's a bit strange to have an exception for
this but it ensures units are shown in familiar millimeters and it also ensures
backwards compatibility.
2013-03-13 17:16:49 +00:00
25c9b56c5a Suppress more uncommon units. 2013-02-11 07:12:15 +00:00
971fca48ca supress Hectograms from being used when displaying weight units since they are not so common. 2013-02-11 01:14:45 +00:00
f213ae0b19 style cleanup 2012-11-01 09:54:00 +00:00
aa49ca25d5 incorrect spelling in comments 2012-09-26 20:05:38 +00:00
b96c622015 style cleanup 2012-08-11 22:12:32 +00:00
715edceb42 spelling cleanup: metre -> er 2012-07-04 12:56:58 +00:00
32478997ec style cleanup 2012-06-27 18:29:47 +00:00
57b488574a style cleanup: comma placement 2012-05-23 22:45:39 +00:00
e701f9b670 style cleanup: whitespace / commas 2012-04-29 15:47:02 +00:00
f627745053 aparently yards are not used a lot, suppress their use in button display (input still knows about them) - was reported as a bug.
also fix minor rip bug where active selection was lost.
2012-04-20 14:59:24 +00:00
a73d0d3e72 code cleanup: dont include BLI_winstuff.h on non windows systems, also cleanup some defines/includes for windows. 2012-04-15 07:54:07 +00:00
3c6239f8be fix for unit system incorrectly replacint 'um' (unicode 'u'). with meters.
result was editing number buttons with um would give a python error.
2012-04-10 02:51:24 +00:00
6fef7f1c32 style cleanup: unit code 2012-03-10 14:20:55 +00:00
4f7bdc59d3 style cleanup: spelling.
also remove large, duplicate comments from sunsky.h
2012-03-09 00:41:09 +00:00
31d2ee9bf7 style cleanup, brackets in else/if, some indentation. 2012-03-06 18:40:15 +00:00
95670e03a0 style cleanup / comment formatting for bli/bke/bmesh 2012-03-03 20:19:11 +00:00