Commit Graph

2730 Commits

Author SHA1 Message Date
Damien Picard
8564e03cdf Fix FPS menu in "Format" panel not following translation setting
The FPS menu was using a cached value which wasn't being refreshed
when translation changed.

Add `bpy.app.handlers.translation_update_post` handler which runs
when translation changes, this can be used to clear any cached UI
values.

Ref !117049
2024-01-18 11:31:38 +11:00
Campbell Barton
7dd81cad94 Fix #117188: Context.temp_override() failed with full-screen areas
Using screen changing functions with screens used for full screen areas
isn't supported & caused corrupt screen data.

Add checks that the current and overriding screen support switching,
raising an error when they don't. Also add a check when restoring the
context not to change any full screen areas.
2024-01-17 16:18:54 +11:00
Hans Goudey
3e76a1a6c2 Cleanup: Move BKE_lib_id.h to C++ 2024-01-15 12:44:14 -05:00
Thomas Barlow
fdb56c4e8d RNA: Speed up raw array access when the property is stored contiguously
Recent and ongoing efforts have changed many properties to be stored
contiguously in memory, e.g. mesh attributes. This patch updates
rna_raw_access to make use of this and copy the entire contiguous block
of memory when the property is stored contiguously.

This is faster and scales much better with larger arrays.

Pull Request: https://projects.blender.org/blender/blender/pulls/116015
2024-01-15 17:17:02 +01:00
Campbell Barton
fb532784e1 Docs: add doc-strings for some GPU_matrix functions
Also note the use of flat-array length for PyRNA foreach get/set.
2024-01-15 14:28:37 +11:00
Campbell Barton
c00cd902ce Cleanup: use usernames in code-comments
Also remove my name in a few cases where it doesn't seem necessary.
2024-01-14 11:50:02 +11:00
Thomas Barlow
5139a9c064 Fix: foreach_get/set does not work on multidimensional arrays
The foreach_get/foreach_set methods of bpy_prop_array get/set the entire
contents of the array, but they were checking that the length of the
input sequence was equal to the length of the current array dimension
rather than the total length of all dimensions of the array.

This would read/write memory after the end of the passed in sequence
when the property was a multidimensional array. Performing
`foreach_get` with a Python list with length matching the length of the
current dimension of a multidimensional array would crash a debug build
due to the trailing pad bytes of the temporarily allocated array being
overwritten.

This patch fixes `pyprop_array_foreach_getset` by changing the function
used to get the expected sequence size, to the RNA function that gets
the total length of the array across all its dimensions.

The tests have be updated to additionally test multidimensional array
properties.

Pull Request: https://projects.blender.org/blender/blender/pulls/116457
2024-01-12 18:38:32 +01:00
Damien Picard
5db82be74f Fix #76101: I18n: add new preference to translate reports
Translation of the UI is currently split into 3 preferences:
interface, tooltips, and new data. The distinction between interface
and tooltips is currently unclear as tooltips also include a lot of
messages not displayed in the actual tooltips on mouse hover.

These include reports to the Info Editor, information in editor
headers and footers, and statuses in panels.

In order to limit the use of `TIP_()` to actual tooltips, this commit
introduces a new preference for this extra information: "Reports".

New translation macros are introduced: `RPT_()` and `CTX_RPT_()`, as
well as their equivalent for the Python API, `pgettext_rpt_()`, to be
imported as `rpt_()`.

Pull Request: https://projects.blender.org/blender/blender/pulls/116804
2024-01-12 13:37:29 +01:00
Thomas Barlow
992ec6487b RNA: Add missing raw types for DNA types
RNA raw types were missing for the int8_t, uchar (uint8_t),
ushort (uint16_t), int64_t and uint64_t DNA types types.

This adds the missing RNA raw types for all DNA types that can have
raw access.

Functional Changes

Properties with one of the new unsigned raw types will raise a Python
OverflowError in foreach_getset when attempting to read a negative
integer from bpy_prop_collection.foreach_set(). This is similar to the
existing behaviour of providing a Python int which is too large to
represent as a C long. The existing foreach_getset code will print
the OverflowError and then raise a TypeError instead.

CPython's signed integer parsing functions accept numeric types that are
not the Python int instances by calling their __index__() method.
CPython's unsigned integer parsing functions, however, only accept
Python int instances. To make foreach_getset accept the same
numeric types for unsigned raw types as it already accepts for signed
raw types, the unsigned integer parsing functions in py_capi_utils.h
have been updated to also call the __index__() method when given an
argument which is not a Python int instance.

Because the new unsigned integer parsing in foreach_getset is using
the PyC_ family of functions, which perform their own overflow checks,
the existing signed integer parsing has also been updated to use the
PyC_ family of functions for signed integer parsing. Previously,
OverflowError would only have been raised when the parsed integer was
too large to fit in a C long. With this patch, OverflowError will be
raised whenever the parsed integer is too large to fit in the property's
raw type. Integer properties already have well-defined maximum and
minimum values which should fit within the property's raw type, and enum
properties have a fixed number of values they can take depending on
their items. The bigger change here, is that setting bool properties
which use PROP_RAW_BOOLEAN will now only accept 0/False and
1/True.

Now that PROP_RAW_CHAR parsing is using PyC_Long_AsU8,
signed char buffers ("b" format) have been updated to no longer be
considered compatible with PROP_RAW_CHAR, matching the behaviour of
the other unsigned types only being considered compatible with unsigned
buffer formats.

The int64_t and uint64_t types can currently only be used by bool
properties (see IS_DNATYPE_BOOLEAN_COMPAT and the other macros in
RNA_define.hh), but bool properties only have raw access when they do
not use a bitmask and it doesn't make much sense to use an entire 64
bits just for a single bool property, so PROP_RAW_INT64 and
PROP_RAW_UINT64 are expected to be unused.

Performance Changes

Providing raw types allows for faster access through
rna_access.cc#rna_raw_access, especially when a buffer compatible with
the property's raw type is passed through from
bpy_rna.cc#foreach_getset.

Before this patch, the bpy.types.Keyframe.handle_left_type property
did not have raw access, so foreach_getset would fall back to
PROP_RAW_INT being the compatible type and then use the slower loop in
rna_raw_access.

With this patch, the bpy.types.Keyframe.handle_left_type property has
raw access with the PROP_RAW_UINT8 type. Using a buffer compatible
with this raw type can use the faster memcpy loop in
rna_raw_access. Using a Python list will iterate the list into an
array whose type matches PROP_RAW_UINT8, which will also use the
faster memcpy loop in #rna_raw_access.

Pull Request: https://projects.blender.org/blender/blender/pulls/115761
RNA raw types were missing for the int8_t, uchar (uint8_t),
ushort (uint16_t), int64_t and uint64_t DNA types types.

This adds the missing RNA raw types for all DNA types that can have
raw access.

Functional Changes

Properties with one of the new unsigned raw types will raise a Python
OverflowError in foreach_getset when attempting to read a negative
integer from bpy_prop_collection.foreach_set(). This is similar to the
existing behaviour of providing a Python int which is too large to
represent as a C long. The existing foreach_getset code will print
the OverflowError and then raise a TypeError instead.

CPython's signed integer parsing functions accept numeric types that are
not the Python int instances by calling their __index__() method.
CPython's unsigned integer parsing functions, however, only accept
Python int instances. To make foreach_getset accept the same
numeric types for unsigned raw types as it already accepts for signed
raw types, the unsigned integer parsing functions in py_capi_utils.h
have been updated to also call the __index__() method when given an
argument which is not a Python int instance.

Because the new unsigned integer parsing in foreach_getset is using
the PyC_ family of functions, which perform their own overflow checks,
the existing signed integer parsing has also been updated to use the
PyC_ family of functions for signed integer parsing. Previously,
OverflowError would only have been raised when the parsed integer was
too large to fit in a C long. With this patch, OverflowError will be
raised whenever the parsed integer is too large to fit in the property's
raw type. Integer properties already have well-defined maximum and
minimum values which should fit within the property's raw type, and enum
properties have a fixed number of values they can take depending on
their items. The bigger change here, is that setting bool properties
which use PROP_RAW_BOOLEAN will now only accept 0/False and
1/True.

Now that PROP_RAW_CHAR parsing is using PyC_Long_AsU8,
signed char buffers ("b" format) have been updated to no longer be
considered compatible with PROP_RAW_CHAR, matching the behaviour of
the other unsigned types only being considered compatible with unsigned
buffer formats.

The int64_t and uint64_t types can currently only be used by bool
properties (see IS_DNATYPE_BOOLEAN_COMPAT and the other macros in
RNA_define.hh), but bool properties only have raw access when they do
not use a bitmask and it doesn't make much sense to use an entire 64
bits just for a single bool property, so PROP_RAW_INT64 and
PROP_RAW_UINT64 are expected to be unused.

Performance Changes

Providing raw types allows for faster access through
rna_access.cc#rna_raw_access, especially when a buffer compatible with
the property's raw type is passed through from
bpy_rna.cc#foreach_getset.

Before this patch, the bpy.types.Keyframe.handle_left_type property
did not have raw access, so foreach_getset would fall back to
PROP_RAW_INT being the compatible type and then use the slower loop in
rna_raw_access.

With this patch, the bpy.types.Keyframe.handle_left_type property has
raw access with the PROP_RAW_UINT8 type. Using a buffer compatible
with this raw type can use the faster memcpy loop in
rna_raw_access. Using a Python list will iterate the list into an
array whose type matches PROP_RAW_UINT8, which will also use the
faster memcpy loop in #rna_raw_access.

Pull Request: https://projects.blender.org/blender/blender/pulls/115761
2024-01-10 18:19:24 +01:00
Campbell Barton
59dc67974a PyAPI: support returning non ID types when accessing Context.property
Previously accessing properties without an associated ID would return
None, even when the non-ID data was available.

Ref !116981
2024-01-10 23:43:29 +11:00
Campbell Barton
15843b46ab Fix #116854: context.property access crashes when properties have no ID
Missing checks in [0] which didn't account for UI properties without an
ID or failure to create the property path.

[0]: 6ba0346797
2024-01-10 13:46:22 +11:00
Campbell Barton
e1f04aee4b PyAPI: remove code for Python 3.10 2024-01-10 10:04:10 +11:00
Campbell Barton
4d9063739c Cleanup: use RNA_STACK_ARRAY define, avoid extra loop 2024-01-10 10:01:40 +11:00
Thomas Barlow
904b572487 Fix #116807: Crash for large multidimensional bpy property default value
The functions for creating bpy vector properties used fixed size
`default_value` arrays on the stack. The array was not large enough to
store all the default values for larger multidimensional properties,
which would write past the end of the array and start corrupting the
stack, leading to crashes.

The maximum total length of a bpy vector property is 32768 (32x32x32)
which is a little large of an array to be putting on the stack, so the
`default_value` array now uses `blender::Array` and allocates additional
memory if the number of `default_value` elements exceeds its inline
buffer size of 64.

To simplify allocating arrays of the correct size,
#bpy_prop_array_length_parse now fills in `array_len_info->len_total`
when parsing a sequence.

Pull Request: https://projects.blender.org/blender/blender/pulls/116811
2024-01-09 22:40:13 +01:00
Campbell Barton
5afd33d129 PyAPI: drop support for Python 3.10
All platforms have been updated to support 3.11
so supporting 3.10 is no longer needed.
2024-01-09 22:23:41 +11:00
Alexander Gavrilov
d0ef66ddff Drivers: implement fallback values for RNA path based variables.
As discussed in #105407, it can be useful to support returning
a fallback value specified by the user instead of failing the driver
if a driver variable cannot resolve its RNA path. This especially
applies to context variables referencing custom properties, since
when the object with the driver is linked into another scene, the
custom property can easily not exist there.

This patch adds an optional fallback value setting to properties
based on RNA path (including ordinary Single Property variables
due to shared code and similarity). When enabled, RNA path lookup
failures (including invalid array index) cause the fallback value
to be used instead of marking the driver invalid.

A flag is added to track when this happens for UI use. It is
also exposed to python for lint type scripts.

When the fallback value is used, the input field containing
the property RNA path that failed to resolve is highlighted in red
(identically to the case without a fallback), and the driver
can be included in the With Errors filter of the Drivers editor.
However, the channel name is not underlined in red, because
the driver as a whole evaluates successfully.

Pull Request: https://projects.blender.org/blender/blender/pulls/110135
2024-01-08 15:24:59 +01:00
Alexander Gavrilov
bbd7872680 Drivers: refactor driver_get_variable_property to return an enum.
In order to prepare for introduction of fallbacks, refactor the
function to return its status as an enumeration value. Also, move
the index range check inside the function from python-specific code.
2024-01-08 16:08:18 +02:00
Brecht Van Lommel
d377ef2543 Clang Format: bump to version 17
Along with the 4.1 libraries upgrade, we are bumping the clang-format
version from 8-12 to 17. This affects quite a few files.

If not already the case, you may consider pointing your IDE to the
clang-format binary bundled with the Blender precompiled libraries.
2024-01-03 13:38:14 +01:00
Campbell Barton
69d22a42d0 Fix #116297: Context override error passing in a window without a screen
When overriding the contexts window but not the screen, the context
override would attempt to use the current screen with the new window.

This raised an error and could crash when editing properties in the
key-map editor for the "context toggle" operator.
2023-12-19 11:09:28 +11:00
Campbell Barton
2b3c379850 Cleanup: use boolean & nullptr literals 2023-12-17 16:04:44 +11:00
Bastien Montagne
f01bc93bcf Cleanup: Move BKE_blendfile headers to CPP. 2023-12-13 12:36:45 +01:00
Hans Goudey
8157f33911 Cleanup: Move opensubdiv C-API headers to C++
All the relevant code is C++ now, so we don't need to complicate things
with the trip through C anymore. We will still need some wrappers, since
opensubdiv is an optional dependency though. The goal is to make it
simpler to remove the unnecessary/costly abstraction levels between
Blender mesh data and the opensubdiv code.
2023-12-11 07:50:29 -05:00
Campbell Barton
12c4d22e6d Fix #115937: Context override fails to restore screen
The recent addition screen override [0] failed to account for the
override windows screen being overridden when restoring the context.

When overriding the window and screen, it's incorrect to use the
original contexts screen when restoring the screen of the overriding
window.

This window's screen may not be in the original context or the
overriding screen. Resolve the bug by storing this separately
and use it when restoring the context.

[0]: 6af92e1360
2023-12-10 23:33:08 +11:00
Campbell Barton
49c6e4ed5a PyAPI: micro optimization accessing keyword arguments for bpy functions
Check the string length before comparing with memcmp,
gives 20-30% speedup for the lookup function.
2023-12-10 16:18:35 +11:00
Guillermo Venegas
7c5fa8bf6c IO: Add initial support for File Handlers registration
Adds initial support for File Handler registration with the python API
for design task #68935. File Handlers will allow developers to associate
additional UI behavior and capability to operators traditionally used
only within the file browser.

The initial commit should have no user visible changes, but will serve
as the foundation for providing file drag & drop capabilities to
operators that can manage files (#111242).

See the PR for an example of python usage.
See design task #68935 for remaining work to be explored in the future.

Pull Request: https://projects.blender.org/blender/blender/pulls/112466
2023-12-09 05:06:10 +01:00
Jeroen Bakker
65e58fe574 CMake: Fix Compiling Shader Builder on macOS
Due to changes in the build environment shader_builder wasn't able to
compile on macOs. This patch reverts several recent changes to CMake files.

* dbb2844ed9
* 94817f64b9
* 1b6cd937ff

The idea is that in the near future shader_builder will run on the buildbot as
part of any regular build to ensure that changes to the CMake doesn't break
shader_builder and we only detect it after a few days.

Pull Request: https://projects.blender.org/blender/blender/pulls/115929
2023-12-08 15:47:14 +01:00
Campbell Barton
9c5ddd17aa PyAPI: support global window areas with Context.temp_override
Check for the windows global areas as well as screen areas when
validating context members before assigning.
2023-12-08 16:32:16 +11:00
Campbell Barton
1ec10323ff Fix Context.temp_override restoring freed values on exist
Since windowing data may have been freed, validate the members
before restoring them when the context-manager exits.
2023-12-08 16:23:08 +11:00
Campbell Barton
328d5bcc3c Fix Context.temp_override(..) use with temporary screens
Subtle regression in [0] caused context override to fail when
passing in the current context when a temporary screen was used.

While passing in a temporary screen as an override isn't supported,
this shouldn't raise an exception if the argument matches the current
context.

Also added sanity check that the window passed in exists
and code comments to give an explanation of the current behavior.

[0]: 6af92e1360
2023-12-08 16:22:21 +11:00
Campbell Barton
497600e49e Cleanup: spelling in comments, strings 2023-12-07 12:45:27 +11:00
Campbell Barton
bad4390663 Cleanup: format, function style cast 2023-12-07 11:42:12 +11:00
Campbell Barton
9898602e9d Cleanup: clarify #ifndef checks in trailing #endif comments 2023-12-07 10:38:54 +11:00
Brecht Van Lommel
e06561a27a Build: replace Blender specific DEBUG by standard NDEBUG
NDEBUG is part of the C standard and disables asserts. Only this will
now be used to decide if asserts are enabled.

DEBUG was a Blender specific define, that has now been removed.

_DEBUG is a Visual Studio define for builds in Debug configuration.
Blender defines this for all platforms. This is still used in a few
places in the draw code, and in external libraries Bullet and Mantaflow.

Pull Request: https://projects.blender.org/blender/blender/pulls/115774
2023-12-06 16:05:14 +01:00
Campbell Barton
6af92e1360 PyAPI: support overriding the "screen" with Context.temp_override()
Previously it was checking the actually active screen - it was leading
to the issue where it's no longer possible to override context.screen
(#108763) which was possible with old context override method.

Now the screen can be overridden, keeping the window & workspace
consistent.

Ref !114269.

Co-authored-by: Andrej730 <azhilenkov@gmail.com>
2023-12-06 20:45:36 +11:00
Campbell Barton
6bb875db93 Cleanup: minor correction to exception message, add doxy section 2023-12-06 20:45:35 +11:00
Bastien Montagne
3acb64e7ac BKE_main: move header to be a fully CPP one.
Pull Request: https://projects.blender.org/blender/blender/pulls/115681
2023-12-01 20:38:54 +01:00
Brecht Van Lommel
9ffd6dabf0 Fix build error in freestyle when not using precompiled headers 2023-11-30 14:31:29 +01:00
Campbell Barton
15db0cb446 Cleanup: use style for doxygen comment blocks 2023-11-30 14:15:11 +11:00
Hans Goudey
7e3ba529ea Cleanup: Move four blenkernel headers to C++ 2023-11-28 16:05:12 -05:00
Campbell Barton
d96cdb2231 Cleanup: simplify Python API use running scripts
- Remove unnecessary exception if Py_CompileStringObject fails.
- Remove unnecessary PyErr_Occurred check if Py_CompileStringObject
  succeeds (based on incorrect assumption from [0]).
- Pass closeit=1 to PyRun_FileExFlags so it's responsible for closing
  the file before executing code.
- Remove unnecessary temporary ReportList.

[0]: b9f6d66328
2023-11-28 22:33:09 +11:00
Campbell Barton
41739cd3fd PyAPI: remove use of stub script to execute files on WIN32
Workaround potential C-API `FILE` incompatibility by reading the
file data into memory, compiling & running it - matching existing logic
for text buffers text buffers. This replaces the in-lined stub-script
that re-opened the file from Python.

While the down-side of the stub-script was minor, it required some
non-obvious logic and had the disadvantage of requiring 2x scripts to
execute whenever a file was executed on WIN32.

Expose BLI_file_read_data_as_mem_from_handle as a public function
since it's useful to be able to read an existing FILE into memory.
2023-11-28 17:50:28 +11:00
Campbell Barton
48bc74953c PyAPI: raise an error when executing a directory on non-Windows systems
Passing a directory to --python would run it as a script without errors
since the directory would read as an empty file.

Raise an error instead because this is what Python it's self does.

This would already happen on WIN32 because the stub script was
executing the file from Python.
2023-11-28 17:40:07 +11:00
Campbell Barton
d71c449d25 PyAPI: use binary file access running scripts on non-WIN32 platforms
Python itself uses binary file access when opening files so this
shouldn't cause any problems.
2023-11-28 16:59:52 +11:00
Campbell Barton
2e1486da60 PyAPI: call 'sys.excepthook' for text editor exceptions
Resolves #115090, where exceptions from the text editor called
`sys.excepthook` in v3.6 but not in v4.0.

The error was caused by PyC_ExceptionBuffer calling PyErr_Display
instead of PyErr_Print.

While technically a regression in [0], the behavior in 3.6x wasn't
working properly either since a user-defined `sys.excepthook` could
prevent PyC_ExceptionBuffer from accessing the exception text.

Resolve with the following changes:

- BPy_errors_to_report has been updated not to print errors.
  Previously BPy_errors_to_report would *sometimes* print the error,
  which complicated situations where the caller wanted predictable
  behavior (always printing or never printing).

- `PyErr_Print()` must be used to display errors to the output,
  this will call `sys.excepthook` as it used to.

It's better not to rely on side effects of BPy_errors_to_report()
for error handling.

[0]: 6a0f98aeef
2023-11-28 13:13:41 +11:00
Ray Molenkamp
1b6cd937ff Cleanup: CMake: Modernize bf_imbuf dependencies
Pretty straightforward

- Remove any bf_imbuf paths from INC
- Add a dependency though LIB when missing

context: https://devtalk.blender.org/t/cmake-cleanup/30260

Pull Request: https://projects.blender.org/blender/blender/pulls/115425
2023-11-25 23:37:24 +01:00
Ray Molenkamp
6b70c04724 Cleanup: CMake: Modernize bf_depsgraph dependencies
Pretty straightforward

- Remove any bf_depsgraph paths from INC
- Add a dependency though LIB when missing

context: https://devtalk.blender.org/t/cmake-cleanup/30260

Pull Request: https://projects.blender.org/blender/blender/pulls/115422
2023-11-25 22:51:59 +01:00
Ray Molenkamp
b683bcc46c Cleanup: CMake: Modernize bf_intern_clog dependencies
Pretty straightforward

- Remove any bf_intern_clog paths from INC
- Add a dependency though LIB when missing

context: https://devtalk.blender.org/t/cmake-cleanup/30260

Pull Request: https://projects.blender.org/blender/blender/pulls/115323
2023-11-24 17:12:24 +01:00
Hans Goudey
29f3d54e91 Cleanup: Grammar in comments
- it's self vs. itself
- boiler plate vs boilerplate
2023-11-21 09:42:39 -05:00
Hans Goudey
3d57bc4397 Cleanup: Move several blenkernel headers to C++
Mostly focus on areas where we're already using C++ features,
where combining C and C++ APIs is getting in the way.

Pull Request: https://projects.blender.org/blender/blender/pulls/114972
2023-11-16 11:41:55 +01:00
nutti
cf41153798 Docs: include cls in bpy.utils.unregister_class
Ref: !114523
2023-11-10 14:32:23 +11:00