2011-10-10 09:38:02 +00:00
|
|
|
/*
|
2002-10-12 11:37:38 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-01-07 19:13:47 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
2016-04-24 22:42:41 +10:00
|
|
|
*
|
|
|
|
* Application level startup/shutdown functionality.
|
2011-02-27 20:40:57 +00:00
|
|
|
*/
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
Giant commit!
A full detailed description of this will be done later... is several days
of work. Here's a summary:
Render:
- Full cleanup of render code, removing *all* globals and bad level calls
all over blender. Render module is now not called abusive anymore
- API-fied calls to rendering
- Full recode of internal render pipeline. Is now rendering tiles by
default, prepared for much smarter 'bucket' render later.
- Each thread now can render a full part
- Renders were tested with 4 threads, goes fine, apart from some lookup
tables in softshadow and AO still
- Rendering is prepared to do multiple layers and passes
- No single 32 bits trick in render code anymore, all 100% floats now.
Writing images/movies
- moved writing images to blender kernel (bye bye 'schrijfplaatje'!)
- made a new Movie handle system, also in kernel. This will enable much
easier use of movies in Blender
PreviewRender:
- Using new render API, previewrender (in buttons) now uses regular render
code to generate images.
- new datafile 'preview.blend.c' has the preview scenes in it
- previews get rendered in exact displayed size (1 pixel = 1 pixel)
3D Preview render
- new; press Pkey in 3d window, for a panel that continuously renders
(pkey is for games, i know... but we dont do that in orange now!)
- this render works nearly identical to buttons-preview render, so it stops
rendering on any event (mouse, keyboard, etc)
- on moving/scaling the panel, the render code doesn't recreate all geometry
- same for shifting/panning view
- all other operations (now) regenerate the full render database still.
- this is WIP... but big fun, especially for simple scenes!
Compositor
- Using same node system as now in use for shaders, you can composit images
- works pretty straightforward... needs much more options/tools and integration
with rendering still
- is not threaded yet, nor is so smart to only recalculate changes... will be
done soon!
- the "Render Result" node will get all layers/passes as output sockets
- The "Output" node renders to a builtin image, which you can view in the Image
window. (yes, output nodes to render-result, and to files, is on the list!)
The Bad News
- "Unified Render" is removed. It might come back in some stage, but this
system should be built from scratch. I can't really understand this code...
I expect it is not much needed, especially with advanced layer/passes
control
- Panorama render, Field render, Motion blur, is not coded yet... (I had to
recode every single feature in render, so...!)
- Lens Flare is also not back... needs total revision, might become composit
effect though (using zbuffer for visibility)
- Part render is gone! (well, thats obvious, its default now).
- The render window is only restored with limited functionality... I am going
to check first the option to render to a Image window, so Blender can become
a true single-window application. :)
For example, the 'Spare render buffer' (jkey) doesnt work.
- Render with border, now default creates a smaller image
- No zbuffers are written yet... on the todo!
- Scons files and MSVC will need work to get compiling again
OK... thats what I can quickly recall. Now go compiling!
2006-01-23 22:05:47 +00:00
|
|
|
|
2016-04-24 22:42:41 +10:00
|
|
|
#include "BLI_string.h"
|
|
|
|
#include "BLI_listbase.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2011-06-24 16:54:30 +00:00
|
|
|
#include "BLI_callbacks.h"
|
2004-11-07 16:49:46 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "IMB_imbuf.h"
|
2011-10-23 17:52:20 +00:00
|
|
|
#include "IMB_moviecache.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2018-02-12 17:24:18 +11:00
|
|
|
#include "BKE_addon.h"
|
2016-04-24 22:42:41 +10:00
|
|
|
#include "BKE_blender.h" /* own include */
|
|
|
|
#include "BKE_blender_version.h" /* own include */
|
2018-06-24 16:07:34 +02:00
|
|
|
#include "BKE_blender_user_menu.h"
|
2016-04-24 22:42:41 +10:00
|
|
|
#include "BKE_blendfile.h"
|
2013-03-19 14:25:12 +00:00
|
|
|
#include "BKE_brush.h"
|
2016-09-19 09:02:31 +02:00
|
|
|
#include "BKE_cachefile.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "BKE_global.h"
|
Key Configuration
Keymaps are now saveable and configurable from the user preferences, note
that editing one item in a keymap means the whole keymap is now defined by
the user and will not be updated by Blender, an option for syncing might be
added later. The outliner interface is still there, but I will probably
remove it.
There's actually 3 levels now:
* Default builtin key configuration.
* Key configuration loaded from .py file, for configs like Blender 2.4x
or other 3D applications.
* Keymaps edited by the user and saved in .B.blend. These can be saved
to .py files as well to make creating distributable configurations
easier.
Also, user preferences sections were reorganized a bit, now there is:
Interface, Editing, Input, Files and System.
Implementation notes:
* wmKeyConfig was added which represents a key configuration containing
keymaps.
* wmKeymapItem was renamed to wmKeyMapItem for consistency with wmKeyMap.
* Modal maps are not wrapped yet.
* User preferences DNA file reading did not support newdataadr() yet,
added this now for reading keymaps.
* Key configuration related settings are now RNA wrapped.
* is_property_set and is_property_hidden python methods were added.
2009-10-08 18:40:03 +00:00
|
|
|
#include "BKE_idprop.h"
|
2012-11-15 15:59:58 +00:00
|
|
|
#include "BKE_image.h"
|
2017-05-03 11:38:17 +02:00
|
|
|
#include "BKE_layer.h"
|
2018-11-07 16:06:36 +01:00
|
|
|
#include "BKE_main.h"
|
2007-03-31 18:18:30 +00:00
|
|
|
#include "BKE_node.h"
|
2008-12-19 00:50:21 +00:00
|
|
|
#include "BKE_report.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "BKE_scene.h"
|
2008-12-08 15:02:57 +00:00
|
|
|
#include "BKE_screen.h"
|
2009-12-13 14:56:45 +00:00
|
|
|
#include "BKE_sequencer.h"
|
2018-06-20 09:29:40 +02:00
|
|
|
#include "BKE_studiolight.h"
|
Holiday coding log :)
Nice formatted version (pictures soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability
Short list of main changes:
- Transparent region option (over main region), added code to blend in/out such panels.
- Min size window now 640 x 480
- Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake.
- Macbook retina support, use command line --no-native-pixels to disable it
- Timeline Marker label was drawing wrong
- Trackpad and magic mouse: supports zoom (hold ctrl)
- Fix for splash position: removed ghost function and made window size update after creation immediate
- Fast undo buffer save now adds UI as well. Could be checked for regular file save even...
Quit.blend and temp file saving use this now.
- Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)"
- New Userpref option "Keep Session" - this always saves quit.blend, and loads on start.
This allows keeping UI and data without actual saves, until you actually save.
When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header)
- Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v).
Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards.
- User preferences (themes, keymaps, user settings) now can be saved as a separate file.
Old option is called "Save Startup File" the new one "Save User Settings".
To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still.
- OSX: fixed bug that stopped giving mouse events outside window.
This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
|
|
|
|
2017-04-06 16:11:50 +02:00
|
|
|
#include "DEG_depsgraph.h"
|
|
|
|
|
2012-03-26 08:10:12 +00:00
|
|
|
#include "RE_pipeline.h"
|
Fix T42139, vertical noise stripe patterns in noise texture.
Two fixes here (only the second one is strictly needed to fix the issue,
but both make the system better).
First is introduction of a random generator array for use with threaded
systems where each thread needs to access its own number generator.
The random texture now uses this so it should not be influenced by other
random generator reseedings of the main random generator like it did
before.
Second, I reshuffled the texture code to resample the upper bits of the
random number first. According to Numerical Recipes, this is where the
most variance can be found, so by sampling those we avoid correlation
issues. Also, multiplying here is not ideal because if a pair of bits
are zero, then the whole result will also be zero.
Overall this is much more random (tm) than before, however result will
also be brighter, since we now have less black spots. Tweaking the
brightness/contrast should somewhat fix that, generally having the same
result as before is not possible anyway if we are to really fix this.
Also, seems like exposing procedural depth might be nice here since it
influences the precision of the texture lookup.
2014-10-09 15:48:38 +02:00
|
|
|
#include "RE_render_ext.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
Holiday coding log :)
Nice formatted version (pictures soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability
Short list of main changes:
- Transparent region option (over main region), added code to blend in/out such panels.
- Min size window now 640 x 480
- Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake.
- Macbook retina support, use command line --no-native-pixels to disable it
- Timeline Marker label was drawing wrong
- Trackpad and magic mouse: supports zoom (hold ctrl)
- Fix for splash position: removed ghost function and made window size update after creation immediate
- Fast undo buffer save now adds UI as well. Could be checked for regular file save even...
Quit.blend and temp file saving use this now.
- Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)"
- New Userpref option "Keep Session" - this always saves quit.blend, and loads on start.
This allows keeping UI and data without actual saves, until you actually save.
When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header)
- Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v).
Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards.
- User preferences (themes, keymaps, user settings) now can be saved as a separate file.
Old option is called "Save Startup File" the new one "Save User Settings".
To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still.
- OSX: fixed bug that stopped giving mouse events outside window.
This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
|
|
|
#include "BLF_api.h"
|
|
|
|
|
2012-05-08 22:07:06 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
Global G;
|
|
|
|
UserDef U;
|
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
char versionstr[48] = "";
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* ********** free ********** */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2008-12-08 15:02:57 +00:00
|
|
|
/* only to be called on exit blender */
|
2016-04-24 22:42:41 +10:00
|
|
|
void BKE_blender_free(void)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2018-06-13 10:57:10 +02:00
|
|
|
/* samples are in a global list..., also sets G_MAIN->sound->sample NULL */
|
2018-06-20 09:29:40 +02:00
|
|
|
|
|
|
|
BKE_studiolight_free(); /* needs to run before main free as wm is still referenced for icons preview jobs */
|
2018-06-13 10:57:10 +02:00
|
|
|
BKE_main_free(G_MAIN);
|
|
|
|
G_MAIN = NULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2018-03-29 20:38:32 +02:00
|
|
|
if (G.log.file != NULL) {
|
|
|
|
fclose(G.log.file);
|
|
|
|
}
|
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
BKE_spacetypes_free(); /* after free main, it uses space callbacks */
|
2018-06-17 17:05:51 +02:00
|
|
|
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
IMB_exit();
|
2016-09-19 09:02:31 +02:00
|
|
|
BKE_cachefiles_exit();
|
2012-11-15 15:59:58 +00:00
|
|
|
BKE_images_exit();
|
2017-04-06 16:11:50 +02:00
|
|
|
DEG_free_node_types();
|
2013-03-19 14:25:12 +00:00
|
|
|
|
|
|
|
BKE_brush_system_exit();
|
2018-06-17 17:05:51 +02:00
|
|
|
RE_texture_rng_exit();
|
2011-06-24 16:54:30 +00:00
|
|
|
|
2012-05-05 00:23:55 +00:00
|
|
|
BLI_callback_global_finalize();
|
2011-06-24 16:54:30 +00:00
|
|
|
|
2012-08-08 11:56:58 +00:00
|
|
|
BKE_sequencer_cache_destruct();
|
2011-10-23 17:52:20 +00:00
|
|
|
IMB_moviecache_destruct();
|
2017-05-03 11:38:17 +02:00
|
|
|
|
2012-10-21 05:46:41 +00:00
|
|
|
free_nodesystem();
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2017-03-15 14:10:20 +01:00
|
|
|
void BKE_blender_version_string(char *version_str, size_t maxncpy, short version, short subversion, bool v_prefix, bool include_subversion)
|
|
|
|
{
|
|
|
|
const char *prefix = v_prefix ? "v" : "";
|
|
|
|
|
|
|
|
if (include_subversion && subversion > 0) {
|
2017-03-15 15:42:01 +01:00
|
|
|
BLI_snprintf(version_str, maxncpy, "%s%d.%02d.%d", prefix, version / 100, version % 100, subversion);
|
2017-03-15 14:10:20 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
BLI_snprintf(version_str, maxncpy, "%s%d.%02d", prefix, version / 100, version % 100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-24 22:42:41 +10:00
|
|
|
void BKE_blender_globals_init(void)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
memset(&G, 0, sizeof(Global));
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
U.savetime = 1;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2018-06-13 10:57:10 +02:00
|
|
|
G_MAIN = BKE_main_new();
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
strcpy(G.ima, "//");
|
|
|
|
|
2017-03-15 14:10:20 +01:00
|
|
|
BKE_blender_version_string(versionstr, sizeof(versionstr), BLENDER_VERSION, BLENDER_SUBVERSION, true, true);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-04-28 06:20:47 +00:00
|
|
|
#ifndef WITH_PYTHON_SECURITY /* default */
|
2019-02-02 13:39:51 +11:00
|
|
|
G.f |= G_FLAG_SCRIPT_AUTOEXEC;
|
2011-04-28 06:20:47 +00:00
|
|
|
#else
|
2019-02-02 13:39:51 +11:00
|
|
|
G.f &= ~G_FLAG_SCRIPT_AUTOEXEC;
|
2011-04-28 06:20:47 +00:00
|
|
|
#endif
|
2018-03-29 20:38:32 +02:00
|
|
|
|
|
|
|
G.log.level = 1;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2016-04-24 22:42:41 +10:00
|
|
|
void BKE_blender_globals_clear(void)
|
2004-09-05 13:43:51 +00:00
|
|
|
{
|
2018-06-13 10:57:10 +02:00
|
|
|
BKE_main_free(G_MAIN); /* free all lib data */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2018-06-13 10:57:10 +02:00
|
|
|
G_MAIN = NULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2016-04-24 22:42:41 +10:00
|
|
|
/***/
|
2006-11-26 21:17:15 +00:00
|
|
|
|
KEYMAP REFACTORING
Diff Keymaps
User edited keymaps now no longer override the builtin keymaps entirely, but
rather save only the difference and reapply those changes. This means they can
stay better in sync when the builtin keymaps change. The diff/patch algorithm
is not perfect, but better for the common case where only a few items are changed
rather than entire keymaps The main weakness is that if a builtin keymap item
changes, user modification of that item may need to be redone in some cases.
Keymap Editor
The most noticeable change here is that there is no longer an "Edit" button for
keymaps, all are editable immediately, but a "Restore" buttons shows for keymaps
and items that have been edited. Shortcuts for addons can also be edited in the
keymap editor.
Addons
Addons now should only modify the new addon keyconfiguration, the keymap items
there will be added to the builtin ones for handling events, and not get lost
when starting new files. Example code of register/unregister:
km = wm.keyconfigs.addon.keymaps.new("3D View", space_type="VIEW_3D")
km.keymap_items.new('my.operator', 'ESC', 'PRESS')
km = wm.keyconfigs.addon.keymaps["3D View"]
km.keymap_items.remove(km.keymap_items["my.operator"])
Compatibility
The changes made are not forward compatible, i.e. if you save user preferences
with newer versions, older versions will not have key configuration changes that
were made.
2011-08-05 20:45:26 +00:00
|
|
|
static void keymap_item_free(wmKeyMapItem *kmi)
|
|
|
|
{
|
2012-03-24 06:18:31 +00:00
|
|
|
if (kmi->properties) {
|
KEYMAP REFACTORING
Diff Keymaps
User edited keymaps now no longer override the builtin keymaps entirely, but
rather save only the difference and reapply those changes. This means they can
stay better in sync when the builtin keymaps change. The diff/patch algorithm
is not perfect, but better for the common case where only a few items are changed
rather than entire keymaps The main weakness is that if a builtin keymap item
changes, user modification of that item may need to be redone in some cases.
Keymap Editor
The most noticeable change here is that there is no longer an "Edit" button for
keymaps, all are editable immediately, but a "Restore" buttons shows for keymaps
and items that have been edited. Shortcuts for addons can also be edited in the
keymap editor.
Addons
Addons now should only modify the new addon keyconfiguration, the keymap items
there will be added to the builtin ones for handling events, and not get lost
when starting new files. Example code of register/unregister:
km = wm.keyconfigs.addon.keymaps.new("3D View", space_type="VIEW_3D")
km.keymap_items.new('my.operator', 'ESC', 'PRESS')
km = wm.keyconfigs.addon.keymaps["3D View"]
km.keymap_items.remove(km.keymap_items["my.operator"])
Compatibility
The changes made are not forward compatible, i.e. if you save user preferences
with newer versions, older versions will not have key configuration changes that
were made.
2011-08-05 20:45:26 +00:00
|
|
|
IDP_FreeProperty(kmi->properties);
|
|
|
|
MEM_freeN(kmi->properties);
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
if (kmi->ptr)
|
KEYMAP REFACTORING
Diff Keymaps
User edited keymaps now no longer override the builtin keymaps entirely, but
rather save only the difference and reapply those changes. This means they can
stay better in sync when the builtin keymaps change. The diff/patch algorithm
is not perfect, but better for the common case where only a few items are changed
rather than entire keymaps The main weakness is that if a builtin keymap item
changes, user modification of that item may need to be redone in some cases.
Keymap Editor
The most noticeable change here is that there is no longer an "Edit" button for
keymaps, all are editable immediately, but a "Restore" buttons shows for keymaps
and items that have been edited. Shortcuts for addons can also be edited in the
keymap editor.
Addons
Addons now should only modify the new addon keyconfiguration, the keymap items
there will be added to the builtin ones for handling events, and not get lost
when starting new files. Example code of register/unregister:
km = wm.keyconfigs.addon.keymaps.new("3D View", space_type="VIEW_3D")
km.keymap_items.new('my.operator', 'ESC', 'PRESS')
km = wm.keyconfigs.addon.keymaps["3D View"]
km.keymap_items.remove(km.keymap_items["my.operator"])
Compatibility
The changes made are not forward compatible, i.e. if you save user preferences
with newer versions, older versions will not have key configuration changes that
were made.
2011-08-05 20:45:26 +00:00
|
|
|
MEM_freeN(kmi->ptr);
|
|
|
|
}
|
|
|
|
|
2017-11-23 03:10:58 +11:00
|
|
|
void BKE_blender_userdef_data_swap(UserDef *userdef_a, UserDef *userdef_b)
|
2017-03-17 05:10:36 +11:00
|
|
|
{
|
2017-11-23 03:10:58 +11:00
|
|
|
SWAP(UserDef, *userdef_a, *userdef_b);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_blender_userdef_data_set(UserDef *userdef)
|
|
|
|
{
|
|
|
|
BKE_blender_userdef_data_swap(&U, userdef);
|
|
|
|
BKE_blender_userdef_data_free(userdef, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_blender_userdef_data_set_and_free(UserDef *userdef)
|
|
|
|
{
|
|
|
|
BKE_blender_userdef_data_set(userdef);
|
|
|
|
MEM_freeN(userdef);
|
2017-03-17 05:10:36 +11:00
|
|
|
}
|
|
|
|
|
2017-03-20 12:42:19 +11:00
|
|
|
static void userdef_free_keymaps(UserDef *userdef)
|
2009-04-30 16:44:00 +00:00
|
|
|
{
|
2017-03-20 12:42:19 +11:00
|
|
|
for (wmKeyMap *km = userdef->user_keymaps.first, *km_next; km; km = km_next) {
|
|
|
|
km_next = km->next;
|
2017-03-17 00:18:20 +11:00
|
|
|
for (wmKeyMapDiffItem *kmdi = km->diff_items.first; kmdi; kmdi = kmdi->next) {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (kmdi->add_item) {
|
KEYMAP REFACTORING
Diff Keymaps
User edited keymaps now no longer override the builtin keymaps entirely, but
rather save only the difference and reapply those changes. This means they can
stay better in sync when the builtin keymaps change. The diff/patch algorithm
is not perfect, but better for the common case where only a few items are changed
rather than entire keymaps The main weakness is that if a builtin keymap item
changes, user modification of that item may need to be redone in some cases.
Keymap Editor
The most noticeable change here is that there is no longer an "Edit" button for
keymaps, all are editable immediately, but a "Restore" buttons shows for keymaps
and items that have been edited. Shortcuts for addons can also be edited in the
keymap editor.
Addons
Addons now should only modify the new addon keyconfiguration, the keymap items
there will be added to the builtin ones for handling events, and not get lost
when starting new files. Example code of register/unregister:
km = wm.keyconfigs.addon.keymaps.new("3D View", space_type="VIEW_3D")
km.keymap_items.new('my.operator', 'ESC', 'PRESS')
km = wm.keyconfigs.addon.keymaps["3D View"]
km.keymap_items.remove(km.keymap_items["my.operator"])
Compatibility
The changes made are not forward compatible, i.e. if you save user preferences
with newer versions, older versions will not have key configuration changes that
were made.
2011-08-05 20:45:26 +00:00
|
|
|
keymap_item_free(kmdi->add_item);
|
|
|
|
MEM_freeN(kmdi->add_item);
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
if (kmdi->remove_item) {
|
KEYMAP REFACTORING
Diff Keymaps
User edited keymaps now no longer override the builtin keymaps entirely, but
rather save only the difference and reapply those changes. This means they can
stay better in sync when the builtin keymaps change. The diff/patch algorithm
is not perfect, but better for the common case where only a few items are changed
rather than entire keymaps The main weakness is that if a builtin keymap item
changes, user modification of that item may need to be redone in some cases.
Keymap Editor
The most noticeable change here is that there is no longer an "Edit" button for
keymaps, all are editable immediately, but a "Restore" buttons shows for keymaps
and items that have been edited. Shortcuts for addons can also be edited in the
keymap editor.
Addons
Addons now should only modify the new addon keyconfiguration, the keymap items
there will be added to the builtin ones for handling events, and not get lost
when starting new files. Example code of register/unregister:
km = wm.keyconfigs.addon.keymaps.new("3D View", space_type="VIEW_3D")
km.keymap_items.new('my.operator', 'ESC', 'PRESS')
km = wm.keyconfigs.addon.keymaps["3D View"]
km.keymap_items.remove(km.keymap_items["my.operator"])
Compatibility
The changes made are not forward compatible, i.e. if you save user preferences
with newer versions, older versions will not have key configuration changes that
were made.
2011-08-05 20:45:26 +00:00
|
|
|
keymap_item_free(kmdi->remove_item);
|
|
|
|
MEM_freeN(kmdi->remove_item);
|
Key Configuration
Keymaps are now saveable and configurable from the user preferences, note
that editing one item in a keymap means the whole keymap is now defined by
the user and will not be updated by Blender, an option for syncing might be
added later. The outliner interface is still there, but I will probably
remove it.
There's actually 3 levels now:
* Default builtin key configuration.
* Key configuration loaded from .py file, for configs like Blender 2.4x
or other 3D applications.
* Keymaps edited by the user and saved in .B.blend. These can be saved
to .py files as well to make creating distributable configurations
easier.
Also, user preferences sections were reorganized a bit, now there is:
Interface, Editing, Input, Files and System.
Implementation notes:
* wmKeyConfig was added which represents a key configuration containing
keymaps.
* wmKeymapItem was renamed to wmKeyMapItem for consistency with wmKeyMap.
* Modal maps are not wrapped yet.
* User preferences DNA file reading did not support newdataadr() yet,
added this now for reading keymaps.
* Key configuration related settings are now RNA wrapped.
* is_property_set and is_property_hidden python methods were added.
2009-10-08 18:40:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-17 00:18:20 +11:00
|
|
|
for (wmKeyMapItem *kmi = km->items.first; kmi; kmi = kmi->next) {
|
KEYMAP REFACTORING
Diff Keymaps
User edited keymaps now no longer override the builtin keymaps entirely, but
rather save only the difference and reapply those changes. This means they can
stay better in sync when the builtin keymaps change. The diff/patch algorithm
is not perfect, but better for the common case where only a few items are changed
rather than entire keymaps The main weakness is that if a builtin keymap item
changes, user modification of that item may need to be redone in some cases.
Keymap Editor
The most noticeable change here is that there is no longer an "Edit" button for
keymaps, all are editable immediately, but a "Restore" buttons shows for keymaps
and items that have been edited. Shortcuts for addons can also be edited in the
keymap editor.
Addons
Addons now should only modify the new addon keyconfiguration, the keymap items
there will be added to the builtin ones for handling events, and not get lost
when starting new files. Example code of register/unregister:
km = wm.keyconfigs.addon.keymaps.new("3D View", space_type="VIEW_3D")
km.keymap_items.new('my.operator', 'ESC', 'PRESS')
km = wm.keyconfigs.addon.keymaps["3D View"]
km.keymap_items.remove(km.keymap_items["my.operator"])
Compatibility
The changes made are not forward compatible, i.e. if you save user preferences
with newer versions, older versions will not have key configuration changes that
were made.
2011-08-05 20:45:26 +00:00
|
|
|
keymap_item_free(kmi);
|
2017-03-17 00:18:20 +11:00
|
|
|
}
|
KEYMAP REFACTORING
Diff Keymaps
User edited keymaps now no longer override the builtin keymaps entirely, but
rather save only the difference and reapply those changes. This means they can
stay better in sync when the builtin keymaps change. The diff/patch algorithm
is not perfect, but better for the common case where only a few items are changed
rather than entire keymaps The main weakness is that if a builtin keymap item
changes, user modification of that item may need to be redone in some cases.
Keymap Editor
The most noticeable change here is that there is no longer an "Edit" button for
keymaps, all are editable immediately, but a "Restore" buttons shows for keymaps
and items that have been edited. Shortcuts for addons can also be edited in the
keymap editor.
Addons
Addons now should only modify the new addon keyconfiguration, the keymap items
there will be added to the builtin ones for handling events, and not get lost
when starting new files. Example code of register/unregister:
km = wm.keyconfigs.addon.keymaps.new("3D View", space_type="VIEW_3D")
km.keymap_items.new('my.operator', 'ESC', 'PRESS')
km = wm.keyconfigs.addon.keymaps["3D View"]
km.keymap_items.remove(km.keymap_items["my.operator"])
Compatibility
The changes made are not forward compatible, i.e. if you save user preferences
with newer versions, older versions will not have key configuration changes that
were made.
2011-08-05 20:45:26 +00:00
|
|
|
|
|
|
|
BLI_freelistN(&km->diff_items);
|
Key Configuration
Keymaps are now saveable and configurable from the user preferences, note
that editing one item in a keymap means the whole keymap is now defined by
the user and will not be updated by Blender, an option for syncing might be
added later. The outliner interface is still there, but I will probably
remove it.
There's actually 3 levels now:
* Default builtin key configuration.
* Key configuration loaded from .py file, for configs like Blender 2.4x
or other 3D applications.
* Keymaps edited by the user and saved in .B.blend. These can be saved
to .py files as well to make creating distributable configurations
easier.
Also, user preferences sections were reorganized a bit, now there is:
Interface, Editing, Input, Files and System.
Implementation notes:
* wmKeyConfig was added which represents a key configuration containing
keymaps.
* wmKeymapItem was renamed to wmKeyMapItem for consistency with wmKeyMap.
* Modal maps are not wrapped yet.
* User preferences DNA file reading did not support newdataadr() yet,
added this now for reading keymaps.
* Key configuration related settings are now RNA wrapped.
* is_property_set and is_property_hidden python methods were added.
2009-10-08 18:40:03 +00:00
|
|
|
BLI_freelistN(&km->items);
|
2017-03-20 12:42:19 +11:00
|
|
|
|
|
|
|
MEM_freeN(km);
|
Key Configuration
Keymaps are now saveable and configurable from the user preferences, note
that editing one item in a keymap means the whole keymap is now defined by
the user and will not be updated by Blender, an option for syncing might be
added later. The outliner interface is still there, but I will probably
remove it.
There's actually 3 levels now:
* Default builtin key configuration.
* Key configuration loaded from .py file, for configs like Blender 2.4x
or other 3D applications.
* Keymaps edited by the user and saved in .B.blend. These can be saved
to .py files as well to make creating distributable configurations
easier.
Also, user preferences sections were reorganized a bit, now there is:
Interface, Editing, Input, Files and System.
Implementation notes:
* wmKeyConfig was added which represents a key configuration containing
keymaps.
* wmKeymapItem was renamed to wmKeyMapItem for consistency with wmKeyMap.
* Modal maps are not wrapped yet.
* User preferences DNA file reading did not support newdataadr() yet,
added this now for reading keymaps.
* Key configuration related settings are now RNA wrapped.
* is_property_set and is_property_hidden python methods were added.
2009-10-08 18:40:03 +00:00
|
|
|
}
|
2017-03-20 12:42:19 +11:00
|
|
|
BLI_listbase_clear(&userdef->user_keymaps);
|
|
|
|
}
|
2017-03-17 00:18:20 +11:00
|
|
|
|
2018-11-16 11:24:49 +11:00
|
|
|
static void userdef_free_keyconfig_prefs(UserDef *userdef)
|
|
|
|
{
|
2018-11-19 06:14:20 +11:00
|
|
|
for (wmKeyConfigPref *kpt = userdef->user_keyconfig_prefs.first, *kpt_next; kpt; kpt = kpt_next) {
|
2018-11-16 11:24:49 +11:00
|
|
|
kpt_next = kpt->next;
|
|
|
|
IDP_FreeProperty(kpt->prop);
|
|
|
|
MEM_freeN(kpt->prop);
|
|
|
|
MEM_freeN(kpt);
|
|
|
|
}
|
|
|
|
BLI_listbase_clear(&userdef->user_keyconfig_prefs);
|
|
|
|
}
|
|
|
|
|
2018-06-24 16:07:34 +02:00
|
|
|
static void userdef_free_user_menus(UserDef *userdef)
|
|
|
|
{
|
|
|
|
for (bUserMenu *um = userdef->user_menus.first, *um_next; um; um = um_next) {
|
|
|
|
um_next = um->next;
|
|
|
|
BKE_blender_user_menu_item_free_list(&um->items);
|
|
|
|
MEM_freeN(um);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-20 12:42:19 +11:00
|
|
|
static void userdef_free_addons(UserDef *userdef)
|
|
|
|
{
|
2017-03-17 00:18:20 +11:00
|
|
|
for (bAddon *addon = userdef->addons.first, *addon_next; addon; addon = addon_next) {
|
2012-12-29 10:24:42 +00:00
|
|
|
addon_next = addon->next;
|
2018-02-12 17:24:18 +11:00
|
|
|
BKE_addon_free(addon);
|
2012-12-29 10:24:42 +00:00
|
|
|
}
|
2017-03-20 12:42:19 +11:00
|
|
|
BLI_listbase_clear(&userdef->addons);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When loading a new userdef from file,
|
|
|
|
* or when exiting Blender.
|
|
|
|
*/
|
2017-11-23 03:10:58 +11:00
|
|
|
void BKE_blender_userdef_data_free(UserDef *userdef, bool clear_fonts)
|
2017-03-20 12:42:19 +11:00
|
|
|
{
|
|
|
|
#define U _invalid_access_ /* ensure no accidental global access */
|
|
|
|
#ifdef U /* quiet warning */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
userdef_free_keymaps(userdef);
|
2018-11-16 11:24:49 +11:00
|
|
|
userdef_free_keyconfig_prefs(userdef);
|
2018-06-24 16:07:34 +02:00
|
|
|
userdef_free_user_menus(userdef);
|
2017-03-20 12:42:19 +11:00
|
|
|
userdef_free_addons(userdef);
|
2012-12-29 10:24:42 +00:00
|
|
|
|
2017-11-23 03:10:58 +11:00
|
|
|
if (clear_fonts) {
|
|
|
|
for (uiFont *font = userdef->uifonts.first; font; font = font->next) {
|
|
|
|
BLF_unload_id(font->blf_id);
|
|
|
|
}
|
|
|
|
BLF_default_set(-1);
|
2014-06-14 02:23:32 +10:00
|
|
|
}
|
|
|
|
|
2017-03-17 00:18:20 +11:00
|
|
|
BLI_freelistN(&userdef->autoexec_paths);
|
|
|
|
|
|
|
|
BLI_freelistN(&userdef->uistyles);
|
|
|
|
BLI_freelistN(&userdef->uifonts);
|
|
|
|
BLI_freelistN(&userdef->themes);
|
2013-06-18 18:11:52 +00:00
|
|
|
|
2018-06-23 16:31:28 +02:00
|
|
|
|
2017-03-17 00:18:20 +11:00
|
|
|
#undef U
|
2009-04-30 16:44:00 +00:00
|
|
|
}
|
|
|
|
|
2017-03-25 09:29:51 +11:00
|
|
|
/**
|
|
|
|
* Write U from userdef.
|
|
|
|
* This function defines which settings a template will override for the user preferences.
|
|
|
|
*/
|
2017-11-23 03:10:58 +11:00
|
|
|
void BKE_blender_userdef_app_template_data_swap(UserDef *userdef_a, UserDef *userdef_b)
|
2017-03-25 09:29:51 +11:00
|
|
|
{
|
|
|
|
/* TODO:
|
|
|
|
* - various minor settings (add as needed).
|
|
|
|
*/
|
|
|
|
|
2017-11-23 03:10:58 +11:00
|
|
|
#define DATA_SWAP(id) \
|
2017-11-23 15:18:22 +11:00
|
|
|
{ \
|
|
|
|
UserDef userdef_tmp; \
|
|
|
|
memcpy(&(userdef_tmp.id), &(userdef_a->id), sizeof(userdef_tmp.id)); \
|
|
|
|
memcpy(&(userdef_a->id), &(userdef_b->id), sizeof(userdef_tmp.id)); \
|
|
|
|
memcpy(&(userdef_b->id), &(userdef_tmp.id), sizeof(userdef_tmp.id)); \
|
|
|
|
}
|
2017-03-25 09:29:51 +11:00
|
|
|
|
2017-11-23 03:10:58 +11:00
|
|
|
#define LIST_SWAP(id) { \
|
|
|
|
SWAP(ListBase, userdef_a->id, userdef_b->id); \
|
|
|
|
} ((void)0)
|
2017-03-25 09:29:51 +11:00
|
|
|
|
2018-01-11 16:08:55 +11:00
|
|
|
#define FLAG_SWAP(id, ty, flags) { \
|
|
|
|
CHECK_TYPE(&(userdef_a->id), ty *); \
|
|
|
|
const ty f = flags; \
|
|
|
|
const ty a = userdef_a->id; \
|
|
|
|
const ty b = userdef_b->id; \
|
2018-01-16 11:40:43 +11:00
|
|
|
userdef_a->id = (userdef_a->id & ~f) | (b & f); \
|
|
|
|
userdef_b->id = (userdef_b->id & ~f) | (a & f); \
|
2018-01-11 16:08:55 +11:00
|
|
|
} ((void)0)
|
|
|
|
|
|
|
|
|
2017-11-23 03:10:58 +11:00
|
|
|
LIST_SWAP(uistyles);
|
|
|
|
LIST_SWAP(uifonts);
|
|
|
|
LIST_SWAP(themes);
|
|
|
|
LIST_SWAP(addons);
|
|
|
|
LIST_SWAP(user_keymaps);
|
|
|
|
|
|
|
|
DATA_SWAP(font_path_ui);
|
|
|
|
DATA_SWAP(font_path_ui_mono);
|
2018-01-04 14:07:45 +11:00
|
|
|
DATA_SWAP(keyconfigstr);
|
2017-03-25 09:29:51 +11:00
|
|
|
|
2018-07-14 23:49:00 +02:00
|
|
|
DATA_SWAP(gizmo_flag);
|
2018-01-12 12:30:58 +11:00
|
|
|
DATA_SWAP(app_flag);
|
2017-12-16 18:32:12 +11:00
|
|
|
|
2018-01-12 12:30:58 +11:00
|
|
|
/* We could add others. */
|
2019-02-28 13:20:21 +11:00
|
|
|
FLAG_SWAP(uiflag, int, USER_SAVE_PROMPT);
|
2018-01-11 16:08:55 +11:00
|
|
|
|
2017-11-23 03:10:58 +11:00
|
|
|
#undef SWAP_TYPELESS
|
|
|
|
#undef DATA_SWAP
|
2018-01-11 16:08:55 +11:00
|
|
|
#undef LIST_SWAP
|
|
|
|
#undef FLAG_SWAP
|
2017-11-23 03:10:58 +11:00
|
|
|
}
|
2017-03-25 09:29:51 +11:00
|
|
|
|
2017-11-23 03:10:58 +11:00
|
|
|
void BKE_blender_userdef_app_template_data_set(UserDef *userdef)
|
|
|
|
{
|
|
|
|
BKE_blender_userdef_app_template_data_swap(&U, userdef);
|
|
|
|
BKE_blender_userdef_data_free(userdef, true);
|
|
|
|
}
|
2017-03-25 09:29:51 +11:00
|
|
|
|
2017-11-23 03:10:58 +11:00
|
|
|
void BKE_blender_userdef_app_template_data_set_and_free(UserDef *userdef)
|
|
|
|
{
|
|
|
|
BKE_blender_userdef_app_template_data_set(userdef);
|
|
|
|
MEM_freeN(userdef);
|
2017-03-25 09:29:51 +11:00
|
|
|
}
|
|
|
|
|
2008-12-30 13:16:14 +00:00
|
|
|
/* ***************** testing for break ************* */
|
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
static void (*blender_test_break_cb)(void) = NULL;
|
2008-12-30 13:16:14 +00:00
|
|
|
|
2015-05-04 12:29:38 +10:00
|
|
|
void BKE_blender_callback_test_break_set(void (*func)(void))
|
2008-12-30 13:16:14 +00:00
|
|
|
{
|
2012-05-06 17:22:54 +00:00
|
|
|
blender_test_break_cb = func;
|
2008-12-30 13:16:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-24 22:42:41 +10:00
|
|
|
int BKE_blender_test_break(void)
|
2008-12-30 13:16:14 +00:00
|
|
|
{
|
|
|
|
if (!G.background) {
|
|
|
|
if (blender_test_break_cb)
|
|
|
|
blender_test_break_cb();
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
return (G.is_break == true);
|
2008-12-30 13:16:14 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 10:05:18 +10:00
|
|
|
|
|
|
|
/** \name Blender's AtExit
|
|
|
|
*
|
|
|
|
* \note Don't use MEM_mallocN so functions can be registered at any time.
|
|
|
|
* \{ */
|
|
|
|
|
2017-02-06 17:42:30 +01:00
|
|
|
static struct AtExitData {
|
2016-06-24 10:05:18 +10:00
|
|
|
struct AtExitData *next;
|
|
|
|
|
|
|
|
void (*func)(void *user_data);
|
|
|
|
void *user_data;
|
|
|
|
} *g_atexit = NULL;
|
|
|
|
|
|
|
|
void BKE_blender_atexit_register(void (*func)(void *user_data), void *user_data)
|
|
|
|
{
|
|
|
|
struct AtExitData *ae = malloc(sizeof(*ae));
|
|
|
|
ae->next = g_atexit;
|
|
|
|
ae->func = func;
|
|
|
|
ae->user_data = user_data;
|
|
|
|
g_atexit = ae;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_blender_atexit_unregister(void (*func)(void *user_data), const void *user_data)
|
|
|
|
{
|
|
|
|
struct AtExitData *ae = g_atexit;
|
|
|
|
struct AtExitData **ae_p = &g_atexit;
|
|
|
|
|
|
|
|
while (ae) {
|
|
|
|
if ((ae->func == func) && (ae->user_data == user_data)) {
|
|
|
|
*ae_p = ae->next;
|
|
|
|
free(ae);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ae_p = &ae;
|
|
|
|
ae = ae->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_blender_atexit(void)
|
|
|
|
{
|
|
|
|
struct AtExitData *ae = g_atexit, *ae_next;
|
|
|
|
while (ae) {
|
|
|
|
ae_next = ae->next;
|
|
|
|
|
|
|
|
ae->func(ae->user_data);
|
|
|
|
|
|
|
|
free(ae);
|
|
|
|
ae = ae_next;
|
|
|
|
}
|
|
|
|
g_atexit = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \} */
|