2011-02-23 10:52:22 +00:00
/*
2007-12-24 18:27:28 +00:00
* * * * * * BEGIN GPL LICENSE BLOCK * * * * *
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
2007-12-24 18:27:28 +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 .
*
2007-12-24 18:27:28 +00:00
* Contributor ( s ) : Blender Foundation 2007
2002-10-12 11:37:38 +00:00
*
2007-12-24 18:27:28 +00:00
* * * * * * END GPL LICENSE BLOCK * * * * *
2002-10-12 11:37:38 +00:00
*/
2011-02-25 14:04:21 +00:00
/** \file blender/windowmanager/intern/wm_files.c
* \ ingroup wm
*/
2002-10-12 11:37:38 +00:00
/* placed up here because of crappy
* winsock stuff .
*/
2011-04-12 15:55:38 +00:00
# include <stddef.h>
2002-10-12 11:37:38 +00:00
# include <string.h>
2010-07-03 17:47:06 +00:00
# include <errno.h>
2002-10-12 11:37:38 +00:00
2011-05-05 18:50:17 +00:00
# include "zlib.h" /* wm_read_exotic() */
2002-10-12 11:37:38 +00:00
# ifdef WIN32
2006-06-12 19:13:17 +00:00
# include <windows.h> /* need to include windows.h so _WIN32_IE is defined */
# ifndef _WIN32_IE
# define _WIN32_IE 0x0400 /* minimal requirements for SHGetSpecialFolderPath on MINGW MSVC has this defined already */
# endif
# include <shlobj.h> /* for SHGetSpecialFolderPath, has to be done before BLI_winstuff because 'near' is disabled through BLI_windstuff */
2003-03-24 01:46:05 +00:00
# include <process.h> /* getpid */
2009-09-06 13:20:05 +00:00
# include "BLI_winstuff.h"
2002-10-12 11:37:38 +00:00
# else
# include <unistd.h> /* getpid */
# endif
2007-12-24 18:27:28 +00:00
2002-10-12 11:37:38 +00:00
# include "MEM_guardedalloc.h"
2006-02-05 19:30:37 +00:00
# include "MEM_CacheLimiterC-Api.h"
2002-10-12 11:37:38 +00:00
# include "BLI_blenlib.h"
# include "BLI_linklist.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"
2002-10-12 11:37:38 +00:00
2011-09-20 07:39:25 +00:00
# include "BLF_translation.h"
2011-06-15 08:28:56 +00:00
2.5: Blender "Animato" - New Animation System
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action.
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves.
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still)
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
2009-01-17 03:12:50 +00:00
# include "DNA_anim_types.h"
# include "DNA_ipo_types.h" // XXX old animation system
2002-10-12 11:37:38 +00:00
# include "DNA_object_types.h"
# include "DNA_space_types.h"
# include "DNA_userdef_types.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
# include "DNA_scene_types.h"
2006-07-04 12:10:37 +00:00
# include "DNA_screen_types.h"
2007-12-24 18:27:28 +00:00
# include "DNA_windowmanager_types.h"
2002-10-12 11:37:38 +00:00
# include "BKE_blender.h"
2008-12-18 02:56:48 +00:00
# include "BKE_context.h"
2010-07-14 09:46:26 +00:00
# include "BKE_depsgraph.h"
2007-11-07 11:14:52 +00:00
# include "BKE_DerivedMesh.h"
2002-10-12 11:37:38 +00:00
# include "BKE_font.h"
# include "BKE_global.h"
2007-12-24 18:27:28 +00:00
# include "BKE_library.h"
2002-10-12 11:37:38 +00:00
# include "BKE_main.h"
# include "BKE_packedFile.h"
2008-12-19 00:50:21 +00:00
# include "BKE_report.h"
2009-08-16 20:37:22 +00:00
# include "BKE_sound.h"
2007-10-31 13:56:07 +00:00
# include "BKE_texture.h"
2011-01-07 19:18:31 +00:00
2002-10-12 11:37:38 +00:00
# include "BLO_readfile.h"
# include "BLO_writefile.h"
2009-02-07 10:00:46 +00:00
# include "RNA_access.h"
2010-05-24 21:52:18 +00:00
# include "IMB_imbuf.h"
# include "IMB_imbuf_types.h"
# include "IMB_thumbs.h"
Port of part of the Interface code to 2.50.
This is based on the current trunk version, so these files should not need
merges. There's two things (clipboard and intptr_t) that are missing in 2.50
and commented out with XXX 2.48, these can be enabled again once trunk is
merged into this branch.
Further this is not all interface code, there are many parts commented out:
* interface.c: nearly all button types, missing: links, chartab, keyevent.
* interface_draw.c: almost all code, with some small exceptions.
* interface_ops.c: this replaces ui_do_but and uiDoBlocks with two operators,
making it non-blocking.
* interface_regions: this is a part of interface.c, split off, contains code to
create regions for tooltips, menus, pupmenu (that one is crashing currently),
color chooser, basically regions with buttons which is fairly independent of
core interface code.
* interface_panel.c and interface_icons.c: not ported over, so no panels and
icons yet. Panels should probably become (free floating) regions?
* text.c: (formerly language.c) for drawing text and translation. this works
but is using bad globals still and could be cleaned up.
Header Files:
* ED_datafiles.h now has declarations for datatoc_ files, so those extern
declarations can be #included instead of repeated.
* The user interface code is in UI_interface.h and other UI_* files.
Core:
* The API for creating blocks, buttons, etc is nearly the same still. Blocks
are now created per region instead of per area.
* The code was made non-blocking, which means that any changes and redraws
should be possible while editing a button. That means though that we need
some sort of persistence even though the blender model is to recreate buttons
for each redraw. So when a new block is created, some matching happens to
find out which buttons correspond to buttons in the previously created block,
and for activated buttons some data is then copied over to the new button.
* Added UI_init/UI_init_userdef/UI_exit functions that should initialize code
in this module, instead of multiple function calls in the windowmanager.
* Removed most static/globals from interface.c.
* Removed UIafterfunc_ I don't think it's needed anymore, and not sure how it
would integrate here?
* Currently only full window redraws are used, this should become per region
and maybe per button later.
Operators:
* Events are currently handled through two operators: button activate and menu
handle. Operators may not be the best way to implement this, since there are
currently some issues with events being missed, but they can become a special
handler type instead, this should not be a big change.
* The button activate operator runs as long as a button is active, and will
handle all interaction with that button until the button is not activated
anymore. This means clicking, text editing, number dragging, opening menu
blocks, etc.
* Since this operator has to be non-blocking, the ui_do_but code needed to made
non-blocking. That means variables that were previously on the stack, now
need to be stored away in a struct such that they can be accessed again when
the operator receives more events.
* Additionally the place in the ui_do_but code indicated the state, now that
needs to be set explicit in order to handle the right events in the right
state. So an activated button can be in one of these states: init, highlight,
wait_flash, wait_release, wait_key_event, num_editing, text_editing,
text_selecting, block_open, exit.
* For each button type an ui_apply_but_* function has also been separated out
from ui_do_but. This makes it possible to continuously apply the button as
text is being typed for example, and there is an option in the code to enable
this. Since the code non-blocking and can deal with the button being deleted
even, it should be safe to do this.
* When editing text, dragging numbers, etc, the actual data (but->poin) is not
being edited, since that would mean data is being edited without correct
updates happening, while some other part of blender may be accessing that
data in the meantime. So data values, strings, vectors are written to a
temporary location and only flush in the apply function.
Regions:
* Menus, color chooser, tooltips etc all create screen level regions. Such menu
blocks give a handle to the button that creates it, which will contain the
results of the menu block once a MESSAGE event is received from that menu
block.
* For this type of menu block the coordinates used to be in window space. They
are still created that way and ui_positionblock still works with window
coordinates, but after that the block and buttons are brought back to region
coordinates since these are now contained in a region.
* The flush/overdraw frontbuffer drawing code was removed, the windowmanager
should have enough information with these screen level regions to have full
control over what gets drawn when and to then do correct compositing.
Testing:
* The header in the time space currently has some buttons to test the UI code.
2008-11-11 18:31:32 +00:00
# include "ED_datafiles.h"
2009-04-30 16:44:00 +00:00
# include "ED_object.h"
2008-11-27 17:58:46 +00:00
# include "ED_screen.h"
2009-11-25 14:27:50 +00:00
# include "ED_sculpt.h"
2010-05-24 21:52:18 +00:00
# include "ED_view3d.h"
2009-01-01 13:15:35 +00:00
# include "ED_util.h"
2008-11-27 17:58:46 +00:00
2011-04-12 15:55:38 +00:00
# include "RE_pipeline.h" /* only to report missing engine */
2009-01-23 17:42:36 +00:00
# include "GHOST_C-api.h"
2011-01-05 14:56:10 +00:00
# include "GHOST_Path-api.h"
2009-01-23 17:42:36 +00:00
Port of part of the Interface code to 2.50.
This is based on the current trunk version, so these files should not need
merges. There's two things (clipboard and intptr_t) that are missing in 2.50
and commented out with XXX 2.48, these can be enabled again once trunk is
merged into this branch.
Further this is not all interface code, there are many parts commented out:
* interface.c: nearly all button types, missing: links, chartab, keyevent.
* interface_draw.c: almost all code, with some small exceptions.
* interface_ops.c: this replaces ui_do_but and uiDoBlocks with two operators,
making it non-blocking.
* interface_regions: this is a part of interface.c, split off, contains code to
create regions for tooltips, menus, pupmenu (that one is crashing currently),
color chooser, basically regions with buttons which is fairly independent of
core interface code.
* interface_panel.c and interface_icons.c: not ported over, so no panels and
icons yet. Panels should probably become (free floating) regions?
* text.c: (formerly language.c) for drawing text and translation. this works
but is using bad globals still and could be cleaned up.
Header Files:
* ED_datafiles.h now has declarations for datatoc_ files, so those extern
declarations can be #included instead of repeated.
* The user interface code is in UI_interface.h and other UI_* files.
Core:
* The API for creating blocks, buttons, etc is nearly the same still. Blocks
are now created per region instead of per area.
* The code was made non-blocking, which means that any changes and redraws
should be possible while editing a button. That means though that we need
some sort of persistence even though the blender model is to recreate buttons
for each redraw. So when a new block is created, some matching happens to
find out which buttons correspond to buttons in the previously created block,
and for activated buttons some data is then copied over to the new button.
* Added UI_init/UI_init_userdef/UI_exit functions that should initialize code
in this module, instead of multiple function calls in the windowmanager.
* Removed most static/globals from interface.c.
* Removed UIafterfunc_ I don't think it's needed anymore, and not sure how it
would integrate here?
* Currently only full window redraws are used, this should become per region
and maybe per button later.
Operators:
* Events are currently handled through two operators: button activate and menu
handle. Operators may not be the best way to implement this, since there are
currently some issues with events being missed, but they can become a special
handler type instead, this should not be a big change.
* The button activate operator runs as long as a button is active, and will
handle all interaction with that button until the button is not activated
anymore. This means clicking, text editing, number dragging, opening menu
blocks, etc.
* Since this operator has to be non-blocking, the ui_do_but code needed to made
non-blocking. That means variables that were previously on the stack, now
need to be stored away in a struct such that they can be accessed again when
the operator receives more events.
* Additionally the place in the ui_do_but code indicated the state, now that
needs to be set explicit in order to handle the right events in the right
state. So an activated button can be in one of these states: init, highlight,
wait_flash, wait_release, wait_key_event, num_editing, text_editing,
text_selecting, block_open, exit.
* For each button type an ui_apply_but_* function has also been separated out
from ui_do_but. This makes it possible to continuously apply the button as
text is being typed for example, and there is an option in the code to enable
this. Since the code non-blocking and can deal with the button being deleted
even, it should be safe to do this.
* When editing text, dragging numbers, etc, the actual data (but->poin) is not
being edited, since that would mean data is being edited without correct
updates happening, while some other part of blender may be accessing that
data in the meantime. So data values, strings, vectors are written to a
temporary location and only flush in the apply function.
Regions:
* Menus, color chooser, tooltips etc all create screen level regions. Such menu
blocks give a handle to the button that creates it, which will contain the
results of the menu block once a MESSAGE event is received from that menu
block.
* For this type of menu block the coordinates used to be in window space. They
are still created that way and ui_positionblock still works with window
coordinates, but after that the block and buttons are brought back to region
coordinates since these are now contained in a region.
* The flush/overdraw frontbuffer drawing code was removed, the windowmanager
should have enough information with these screen level regions to have full
control over what gets drawn when and to then do correct compositing.
Testing:
* The header in the time space currently has some buttons to test the UI code.
2008-11-11 18:31:32 +00:00
# include "UI_interface.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
2009-02-04 18:02:50 +00:00
# include "GPU_draw.h"
2010-10-31 04:11:39 +00:00
# ifdef WITH_PYTHON
2009-11-20 15:01:09 +00:00
# include "BPY_extern.h"
2010-09-12 12:09:31 +00:00
# endif
2002-10-12 11:37:38 +00:00
2007-12-24 18:27:28 +00:00
# include "WM_api.h"
2008-01-01 15:53:38 +00:00
# include "WM_types.h"
2007-12-24 18:27:28 +00:00
# include "wm.h"
2011-02-14 18:20:10 +00:00
# include "wm_files.h"
2009-02-13 13:33:01 +00:00
# include "wm_window.h"
2009-10-20 13:58:53 +00:00
# include "wm_event_system.h"
2002-10-12 11:37:38 +00:00
2010-07-04 15:35:23 +00:00
static void write_history ( void ) ;
Essential cleanup for mess involved with reading files, initializing UI and
patching versions for UI settings.
Currently four different levels of routines for .blend file reading exist;
/* interface level */
1) BIF_init() -> calls 3
2) BIF_read_file() -> calls 11, optional 4
3) BIF_read_homefile() -> calls 11 or 12, and then 4
4) init_userdef_file()
/* kernel level */
11) BKE_read_file() -> calls 21, and then 14
12) BKE_read_file_from_memory() -> calls 22, and then 14
13) BKE_read_file_from_memfile() -> calls 23, and then 14
14) setup_app_data()
/* loader module level */
21) BLO_read_from_file() -> calls 24
22) BLO_read_from_memory() -> calls 24
23) BLO_read_from_memfile() -> calls 24
/* loader module, internal */
24) blo_read_file_internal()
Note:
- BIF_read_homefile() has additional UI initialize calls, like windows fullscreen and executing commandline options
- Reading from memory (12) only happens for the compiled-in .B.blend
- The "memfile" here is a name I gave to the undo "file" structure. Which is constructed out of memory chunks with basic compression features.
- the kernel function setup_app_data() sets globals like "current screen" and "current scene".
So far, so good. The levels as mentioned here clearly distinguish UI from kernel, and should enable for example game loading (runtime) or background (no UI) loading. In the past years however, 'bad level' dependencies were added, and especially the patches for 'file versions' were added in too many places. The latter is evidently a result of the problem that the "UserDef" struct cannot be initialized/patched if there's not a need for a UI.
Here's how the flow goes in four different cases:
----- Starting up Blender, in foreground with UI --------------------
- creator/creator.c, main() -> calls 1
- If the commandline contains a filename, it calls 11
----- Starting up Blender, in background without UI --------------------
- creator/creator.c, main() -> calls 11 if the commandline has a filename
Note: no Userdef is read, nor initialized. Please note that this was already an existing problem for using Yafray, not setting proper file paths in background mode. The Yafray paths don't belong in the User menu.
----- Starting up Blender as a runtime executable --------------------
This only has calls to 22
----- Loading a file from within the UI (with F1, CTRL+O, using pulldowns) -----
Only calls allowed to 2. It detects if a UserDef has been read too, and in that case the init_userdef_file() will be executed.
Hope this is understandable :)
-Ton-
2004-12-08 14:12:47 +00:00
2007-12-24 18:27:28 +00:00
/* To be able to read files without windows closing, opening, moving
we try to prepare for worst case :
- active window gets active screen from file
- restoring the screens from non - active windows
Best case is all screens match , in that case they get assigned to proper window
*/
static void wm_window_match_init ( bContext * C , ListBase * wmlist )
{
2011-01-12 03:41:12 +00:00
wmWindowManager * wm ;
2010-01-13 21:37:13 +00:00
wmWindow * win , * active_win ;
2007-12-24 18:27:28 +00:00
* wmlist = G . main - > wm ;
G . main - > wm . first = G . main - > wm . last = NULL ;
2010-01-13 21:37:13 +00:00
active_win = CTX_wm_window ( C ) ;
2008-12-21 12:43:34 +00:00
/* first wrap up running stuff */
/* code copied from wm_init_exit.c */
for ( wm = wmlist - > first ; wm ; wm = wm - > id . next ) {
2009-01-27 17:12:40 +00:00
WM_jobs_stop_all ( wm ) ;
2008-12-21 12:43:34 +00:00
for ( win = wm - > windows . first ; win ; win = win - > next ) {
CTX_wm_window_set ( C , win ) ; /* needed by operator close callbacks */
2009-11-23 11:49:23 +00:00
WM_event_remove_handlers ( C , & win - > handlers ) ;
WM_event_remove_handlers ( C , & win - > modalhandlers ) ;
2008-12-21 12:43:34 +00:00
ED_screen_exit ( C , win , win - > screen ) ;
}
}
2010-01-13 21:37:13 +00:00
/* reset active window */
CTX_wm_window_set ( C , active_win ) ;
2008-12-31 17:11:42 +00:00
ED_editors_exit ( C ) ;
2007-12-24 18:27:28 +00:00
return ;
if ( wm = = NULL ) return ;
if ( G . fileflags & G_FILE_NO_UI ) return ;
/* we take apart the used screens from non-active window */
for ( win = wm - > windows . first ; win ; win = win - > next ) {
BLI_strncpy ( win - > screenname , win - > screen - > id . name , MAX_ID_NAME ) ;
2008-12-18 02:56:48 +00:00
if ( win ! = wm - > winactive ) {
2007-12-24 18:27:28 +00:00
BLI_remlink ( & G . main - > screen , win - > screen ) ;
//BLI_addtail(screenbase, win->screen);
}
}
}
2006-08-20 15:22:56 +00:00
2007-12-24 18:27:28 +00:00
/* match old WM with new, 4 cases:
1 - no current wm , no read wm : make new default
2 - no current wm , but read wm : that ' s OK , do nothing
3 - current wm , but not in file : try match screen names
4 - current wm , and wm in file : try match ghostwin
*/
2009-02-06 11:11:42 +00:00
2008-12-21 12:43:34 +00:00
static void wm_window_match_do ( bContext * C , ListBase * oldwmlist )
2002-10-12 11:37:38 +00:00
{
2007-12-24 18:27:28 +00:00
wmWindowManager * oldwm , * wm ;
wmWindow * oldwin , * win ;
/* cases 1 and 2 */
2008-12-21 12:43:34 +00:00
if ( oldwmlist - > first = = NULL ) {
2007-12-24 18:27:28 +00:00
if ( G . main - > wm . first ) ; /* nothing todo */
else
wm_add_default ( C ) ;
}
else {
/* cases 3 and 4 */
2009-02-06 11:11:42 +00:00
/* we've read file without wm..., keep current one entirely alive */
2007-12-24 18:27:28 +00:00
if ( G . main - > wm . first = = NULL ) {
2010-07-23 16:50:25 +00:00
/* when loading without UI, no matching needed */
if ( ! ( G . fileflags & G_FILE_NO_UI ) ) {
bScreen * screen = CTX_wm_screen ( C ) ;
/* match oldwm to new dbase, only old files */
for ( wm = oldwmlist - > first ; wm ; wm = wm - > id . next ) {
2009-01-27 17:12:40 +00:00
2010-07-23 16:50:25 +00:00
for ( win = wm - > windows . first ; win ; win = win - > next ) {
/* all windows get active screen from file */
if ( screen - > winid = = 0 )
win - > screen = screen ;
else
win - > screen = ED_screen_duplicate ( win , screen ) ;
2010-11-05 07:35:21 +00:00
BLI_strncpy ( win - > screenname , win - > screen - > id . name + 2 , sizeof ( win - > screenname ) ) ;
2010-07-23 16:50:25 +00:00
win - > screen - > winid = win - > winid ;
}
2007-12-24 18:27:28 +00:00
}
}
2008-12-21 12:43:34 +00:00
G . main - > wm = * oldwmlist ;
2009-02-06 11:11:42 +00:00
/* screens were read from file! */
ED_screens_initialize ( G . main - > wm . first ) ;
2007-12-24 18:27:28 +00:00
}
else {
/* what if old was 3, and loaded 1? */
/* this code could move to setup_appdata */
2008-12-21 12:43:34 +00:00
oldwm = oldwmlist - > first ;
2007-12-24 18:27:28 +00:00
wm = G . main - > wm . first ;
2009-01-27 17:12:40 +00:00
2011-09-28 19:05:47 +00:00
/* preserve key configurations in new wm, to preserve their keymaps */
wm - > keyconfigs = oldwm - > keyconfigs ;
wm - > addonconf = oldwm - > addonconf ;
wm - > defaultconf = oldwm - > defaultconf ;
wm - > userconf = oldwm - > userconf ;
oldwm - > keyconfigs . first = oldwm - > keyconfigs . last = NULL ;
oldwm - > addonconf = NULL ;
oldwm - > defaultconf = NULL ;
oldwm - > userconf = NULL ;
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
2009-01-27 17:12:40 +00:00
/* ensure making new keymaps and set space types */
wm - > initialized = 0 ;
2009-09-28 15:34:15 +00:00
wm - > winactive = NULL ;
2009-01-27 17:12:40 +00:00
2007-12-24 18:27:28 +00:00
/* only first wm in list has ghostwins */
for ( win = wm - > windows . first ; win ; win = win - > next ) {
for ( oldwin = oldwm - > windows . first ; oldwin ; oldwin = oldwin - > next ) {
if ( oldwin - > winid = = win - > winid ) {
win - > ghostwin = oldwin - > ghostwin ;
2009-09-28 15:34:15 +00:00
win - > active = oldwin - > active ;
if ( win - > active )
wm - > winactive = win ;
2010-06-26 13:24:52 +00:00
if ( ! G . background ) /* file loading in background mode still calls this */
GHOST_SetWindowUserData ( win - > ghostwin , win ) ; /* pointer back */
2007-12-24 18:27:28 +00:00
oldwin - > ghostwin = NULL ;
2009-01-23 17:42:36 +00:00
win - > eventstate = oldwin - > eventstate ;
oldwin - > eventstate = NULL ;
2009-04-13 14:39:43 +00:00
/* ensure proper screen rescaling */
win - > sizex = oldwin - > sizex ;
win - > sizey = oldwin - > sizey ;
win - > posx = oldwin - > posx ;
win - > posy = oldwin - > posy ;
2007-12-24 18:27:28 +00:00
}
}
}
2008-12-21 12:43:34 +00:00
wm_close_and_free_all ( C , oldwmlist ) ;
2007-12-24 18:27:28 +00:00
}
}
}
2.5
Summary of ain features:
- Themes and Styles are now editable.
- CTRL+U "Save user defaults" now goes to new .B25.blend, so you
can use 2.4x and 2.5x next to each other. If B25 doesn't exist, it
reads the regular .B.blend
- Press Tkey in 3d window for (unfinished) toolbar WIP. It now only
shows the last operator, if appropriate.
Nkey properties moved to the other side.
A lot of work was done on removing old themes for good and properly
getting it work with the 2.5 region system. Here's some notes;
- Buttons now all have a complete set of colors, based on button classifications
(See outliner -> user prefs -> Interface
- Theme colors have been extended with basic colors for region types.
Currently colors are defined for Window, Header, List/Channels and
for Button/Tool views.
The screen manager handles this btw, so a TH_BACK will always pick the
right backdrop color.
- Menu backdrops are in in Button theme colors. Floating Panels will be in
the per-space type Themes.
- Styles were added in RNA too, but only for the font settings now.
Only Panel font, widget font and widget-label work now. The 'group label'
will be for templates mostly.
Style settings will be expanded with spacing defaults, label conventions,
etc.
- Label text colors are stored in per-space Theme too, to make sure they fit.
Same goes for Panel title color.
Note that 'shadow' for fonts can conflict with text colors; shadow color is
currently stored in Style... shadow code needs a bit of work still.
2009-04-27 13:44:11 +00:00
/* in case UserDef was read, we re-initialize all, and do versioning */
2010-02-21 18:01:41 +00:00
static void wm_init_userdef ( bContext * C )
2.5
Summary of ain features:
- Themes and Styles are now editable.
- CTRL+U "Save user defaults" now goes to new .B25.blend, so you
can use 2.4x and 2.5x next to each other. If B25 doesn't exist, it
reads the regular .B.blend
- Press Tkey in 3d window for (unfinished) toolbar WIP. It now only
shows the last operator, if appropriate.
Nkey properties moved to the other side.
A lot of work was done on removing old themes for good and properly
getting it work with the 2.5 region system. Here's some notes;
- Buttons now all have a complete set of colors, based on button classifications
(See outliner -> user prefs -> Interface
- Theme colors have been extended with basic colors for region types.
Currently colors are defined for Window, Header, List/Channels and
for Button/Tool views.
The screen manager handles this btw, so a TH_BACK will always pick the
right backdrop color.
- Menu backdrops are in in Button theme colors. Floating Panels will be in
the per-space type Themes.
- Styles were added in RNA too, but only for the font settings now.
Only Panel font, widget font and widget-label work now. The 'group label'
will be for templates mostly.
Style settings will be expanded with spacing defaults, label conventions,
etc.
- Label text colors are stored in per-space Theme too, to make sure they fit.
Same goes for Panel title color.
Note that 'shadow' for fonts can conflict with text colors; shadow color is
currently stored in Style... shadow code needs a bit of work still.
2009-04-27 13:44:11 +00:00
{
UI_init_userdef ( ) ;
MEM_CacheLimiter_set_maximum ( U . memcachelimit * 1024 * 1024 ) ;
2010-10-16 15:00:04 +00:00
sound_init ( CTX_data_main ( C ) ) ;
2010-02-27 12:34:49 +00:00
2011-02-21 02:40:48 +00:00
/* needed so loading a file from the command line respects user-pref [#26156] */
if ( U . flag & USER_FILENOUI ) G . fileflags | = G_FILE_NO_UI ;
else G . fileflags & = ~ G_FILE_NO_UI ;
2010-02-27 12:34:49 +00:00
/* set the python auto-execute setting from user prefs */
2011-03-15 08:04:11 +00:00
/* enabled by default, unless explicitly enabled in the command line which overrides */
if ( ( G . f & G_SCRIPT_OVERRIDE_PREF ) = = 0 ) {
if ( ( U . flag & USER_SCRIPT_AUTOEXEC_DISABLE ) = = 0 ) G . f | = G_SCRIPT_AUTOEXEC ;
else G . f & = ~ G_SCRIPT_AUTOEXEC ;
}
2011-10-21 17:37:38 +00:00
2011-09-28 19:11:59 +00:00
/* update tempdir from user preferences */
2011-10-21 17:37:38 +00:00
BLI_init_temporary_dir ( U . tempdir ) ;
2.5
Summary of ain features:
- Themes and Styles are now editable.
- CTRL+U "Save user defaults" now goes to new .B25.blend, so you
can use 2.4x and 2.5x next to each other. If B25 doesn't exist, it
reads the regular .B.blend
- Press Tkey in 3d window for (unfinished) toolbar WIP. It now only
shows the last operator, if appropriate.
Nkey properties moved to the other side.
A lot of work was done on removing old themes for good and properly
getting it work with the 2.5 region system. Here's some notes;
- Buttons now all have a complete set of colors, based on button classifications
(See outliner -> user prefs -> Interface
- Theme colors have been extended with basic colors for region types.
Currently colors are defined for Window, Header, List/Channels and
for Button/Tool views.
The screen manager handles this btw, so a TH_BACK will always pick the
right backdrop color.
- Menu backdrops are in in Button theme colors. Floating Panels will be in
the per-space type Themes.
- Styles were added in RNA too, but only for the font settings now.
Only Panel font, widget font and widget-label work now. The 'group label'
will be for templates mostly.
Style settings will be expanded with spacing defaults, label conventions,
etc.
- Label text colors are stored in per-space Theme too, to make sure they fit.
Same goes for Panel title color.
Note that 'shadow' for fonts can conflict with text colors; shadow color is
currently stored in Style... shadow code needs a bit of work still.
2009-04-27 13:44:11 +00:00
}
2011-05-05 14:21:31 +00:00
/* return codes */
# define BKE_READ_EXOTIC_FAIL_PATH -3 /* file format is not supported */
# define BKE_READ_EXOTIC_FAIL_FORMAT -2 /* file format is not supported */
# define BKE_READ_EXOTIC_FAIL_OPEN -1 /* Can't open the file */
# define BKE_READ_EXOTIC_OK_BLEND 0 /* .blend file */
# define BKE_READ_EXOTIC_OK_OTHER 1 /* other supported formats */
/* intended to check for non-blender formats but for now it only reads blends */
static int wm_read_exotic ( Scene * UNUSED ( scene ) , const char * name )
{
int len ;
gzFile gzfile ;
char header [ 7 ] ;
int retval ;
// make sure we're not trying to read a directory....
len = strlen ( name ) ;
if ( ELEM ( name [ len - 1 ] , ' / ' , ' \\ ' ) ) {
retval = BKE_READ_EXOTIC_FAIL_PATH ;
}
else {
gzfile = gzopen ( name , " rb " ) ;
if ( gzfile = = NULL ) {
retval = BKE_READ_EXOTIC_FAIL_OPEN ;
}
else {
len = gzread ( gzfile , header , sizeof ( header ) ) ;
gzclose ( gzfile ) ;
if ( len = = sizeof ( header ) & & strncmp ( header , " BLENDER " , 7 ) = = 0 ) {
retval = BKE_READ_EXOTIC_OK_BLEND ;
}
else {
//XXX waitcursor(1);
/*
if ( is_foo_format ( name ) ) {
read_foo ( name ) ;
retval = BKE_READ_EXOTIC_OK_OTHER ;
}
else
*/
{
retval = BKE_READ_EXOTIC_FAIL_FORMAT ;
}
//XXX waitcursor(0);
}
}
}
return retval ;
}
2011-05-18 06:27:32 +00:00
void WM_read_file ( bContext * C , const char * filepath , ReportList * reports )
2007-12-24 18:27:28 +00:00
{
int retval ;
2010-07-03 17:47:06 +00:00
/* so we can get the error message */
errno = 0 ;
2010-11-29 13:14:51 +00:00
WM_cursor_wait ( 1 ) ;
2011-06-24 16:54:30 +00:00
BLI_exec_cb ( CTX_data_main ( C ) , NULL , BLI_CB_EVT_LOAD_PRE ) ;
2007-12-24 18:27:28 +00:00
/* first try to append data from exotic file formats... */
2011-11-03 03:00:45 +00:00
/* it throws error box when file doesn't exist and returns -1 */
2008-12-19 18:28:37 +00:00
/* note; it should set some error message somewhere... (ton) */
2011-05-18 06:27:32 +00:00
retval = wm_read_exotic ( CTX_data_scene ( C ) , filepath ) ;
2006-06-21 11:50:57 +00:00
2007-12-24 18:27:28 +00:00
/* we didn't succeed, now try to read Blender file */
2011-01-07 06:50:29 +00:00
if ( retval = = BKE_READ_EXOTIC_OK_BLEND ) {
2010-03-26 11:35:57 +00:00
int G_f = G . f ;
2007-12-24 18:27:28 +00:00
ListBase wmbase ;
2002-10-12 11:37:38 +00:00
2011-11-03 03:00:45 +00:00
/* put aside screens to match with persistent windows later */
2008-12-31 17:11:42 +00:00
/* also exit screens and editors */
2007-12-24 18:27:28 +00:00
wm_window_match_init ( C , & wmbase ) ;
2011-05-18 06:27:32 +00:00
retval = BKE_read_file ( C , filepath , reports ) ;
2009-02-13 13:33:01 +00:00
G . save_over = 1 ;
2002-10-12 11:37:38 +00:00
2010-03-26 11:35:57 +00:00
/* this flag is initialized by the operator but overwritten on read.
* need to re - enable it here else drivers + registered scripts wont work . */
2011-03-15 08:04:11 +00:00
if ( G . f ! = G_f ) {
const int flags_keep = ( G_SCRIPT_AUTOEXEC | G_SCRIPT_OVERRIDE_PREF ) ;
G . f = ( G . f & ~ flags_keep ) | ( G_f & flags_keep ) ;
}
2010-03-26 11:35:57 +00:00
2007-12-24 18:27:28 +00:00
/* match the read WM with current WM */
2009-11-11 04:08:09 +00:00
wm_window_match_do ( C , & wmbase ) ;
WM_check ( C ) ; /* opens window(s), checks keymaps */
2007-12-24 18:27:28 +00:00
// XXX mainwindow_set_filename_to_title(G.main->name);
2002-10-12 11:37:38 +00:00
2011-01-07 06:50:29 +00:00
if ( retval = = BKE_READ_FILE_OK_USERPREFS ) wm_init_userdef ( C ) ; // in case a userdef is read from regular .blend
Essential cleanup for mess involved with reading files, initializing UI and
patching versions for UI settings.
Currently four different levels of routines for .blend file reading exist;
/* interface level */
1) BIF_init() -> calls 3
2) BIF_read_file() -> calls 11, optional 4
3) BIF_read_homefile() -> calls 11 or 12, and then 4
4) init_userdef_file()
/* kernel level */
11) BKE_read_file() -> calls 21, and then 14
12) BKE_read_file_from_memory() -> calls 22, and then 14
13) BKE_read_file_from_memfile() -> calls 23, and then 14
14) setup_app_data()
/* loader module level */
21) BLO_read_from_file() -> calls 24
22) BLO_read_from_memory() -> calls 24
23) BLO_read_from_memfile() -> calls 24
/* loader module, internal */
24) blo_read_file_internal()
Note:
- BIF_read_homefile() has additional UI initialize calls, like windows fullscreen and executing commandline options
- Reading from memory (12) only happens for the compiled-in .B.blend
- The "memfile" here is a name I gave to the undo "file" structure. Which is constructed out of memory chunks with basic compression features.
- the kernel function setup_app_data() sets globals like "current screen" and "current scene".
So far, so good. The levels as mentioned here clearly distinguish UI from kernel, and should enable for example game loading (runtime) or background (no UI) loading. In the past years however, 'bad level' dependencies were added, and especially the patches for 'file versions' were added in too many places. The latter is evidently a result of the problem that the "UserDef" struct cannot be initialized/patched if there's not a need for a UI.
Here's how the flow goes in four different cases:
----- Starting up Blender, in foreground with UI --------------------
- creator/creator.c, main() -> calls 1
- If the commandline contains a filename, it calls 11
----- Starting up Blender, in background without UI --------------------
- creator/creator.c, main() -> calls 11 if the commandline has a filename
Note: no Userdef is read, nor initialized. Please note that this was already an existing problem for using Yafray, not setting proper file paths in background mode. The Yafray paths don't belong in the User menu.
----- Starting up Blender as a runtime executable --------------------
This only has calls to 22
----- Loading a file from within the UI (with F1, CTRL+O, using pulldowns) -----
Only calls allowed to 2. It detects if a UserDef has been read too, and in that case the init_userdef_file() will be executed.
Hope this is understandable :)
-Ton-
2004-12-08 14:12:47 +00:00
2011-01-07 06:50:29 +00:00
if ( retval ! = BKE_READ_FILE_FAIL ) {
2009-09-01 00:52:03 +00:00
G . relbase_valid = 1 ;
2010-05-06 18:25:56 +00:00
if ( ! G . background ) /* assume automated tasks with background, dont write recent file list */
2010-07-04 15:35:23 +00:00
write_history ( ) ;
2009-09-01 00:52:03 +00:00
}
2006-08-20 14:41:13 +00:00
2006-08-16 18:14:42 +00:00
2009-01-27 17:12:40 +00:00
WM_event_add_notifier ( C , NC_WM | ND_FILEREAD , NULL ) ;
2007-12-24 18:27:28 +00:00
// refresh_interface_font();
2009-11-20 15:01:09 +00:00
2010-04-07 08:27:13 +00:00
CTX_wm_window_set ( C , CTX_wm_manager ( C ) - > windows . first ) ;
2010-07-14 09:46:26 +00:00
2010-04-07 08:27:13 +00:00
ED_editors_init ( C ) ;
2011-03-23 14:06:44 +00:00
DAG_on_visible_update ( CTX_data_main ( C ) , TRUE ) ;
2010-04-07 08:27:13 +00:00
2010-10-31 04:11:39 +00:00
# ifdef WITH_PYTHON
2009-11-20 15:01:09 +00:00
/* run any texts that were loaded in and flagged as modules */
2011-01-05 02:08:54 +00:00
BPY_driver_reset ( ) ;
2011-11-03 06:53:52 +00:00
BPY_app_handlers_reset ( FALSE ) ;
2011-01-05 02:08:54 +00:00
BPY_modules_load_user ( C ) ;
2010-01-23 20:43:55 +00:00
# endif
2011-10-02 21:21:14 +00:00
/* important to do before NULL'ing the context */
BLI_exec_cb ( CTX_data_main ( C ) , NULL , BLI_CB_EVT_LOAD_POST ) ;
2010-04-13 22:43:48 +00:00
CTX_wm_window_set ( C , NULL ) ; /* exits queues */
2011-01-03 12:48:16 +00:00
2011-04-13 09:08:55 +00:00
#if 0 /* gives popups on windows but not linux, bug in report API but disable for now to stop users getting annoyed */
2011-04-12 15:55:38 +00:00
/* TODO, make this show in header info window */
{
Scene * sce ;
for ( sce = G . main - > scene . first ; sce ; sce = sce - > id . next ) {
2011-04-13 00:51:48 +00:00
if ( sce - > r . engine [ 0 ] & & BLI_findstring ( & R_engines , sce - > r . engine , offsetof ( RenderEngineType , idname ) ) = = NULL ) {
2011-04-12 15:55:38 +00:00
BKE_reportf ( reports , RPT_WARNING , " Engine not available: '%s' for scene: %s, an addon may need to be installed or enabled " , sce - > r . engine , sce - > id . name + 2 ) ;
}
}
}
2011-04-13 09:08:55 +00:00
# endif
2011-04-12 15:55:38 +00:00
2011-01-03 12:48:16 +00:00
// XXX undo_editmode_clear();
BKE_reset_undo ( ) ;
BKE_write_undo ( C , " original " ) ; /* save current state */
2004-11-07 16:49:46 +00:00
}
2011-01-07 06:50:29 +00:00
else if ( retval = = BKE_READ_EXOTIC_OK_OTHER )
2009-02-07 10:00:46 +00:00
BKE_write_undo ( C , " Import file " ) ;
2011-01-07 06:50:29 +00:00
else if ( retval = = BKE_READ_EXOTIC_FAIL_OPEN ) {
2011-10-20 20:38:26 +00:00
BKE_reportf ( reports , RPT_ERROR , IFACE_ ( " Can't read file: \" %s \" , %s. " ) , filepath ,
errno ? strerror ( errno ) : IFACE_ ( " Unable to open the file " ) ) ;
2008-12-29 13:38:08 +00:00
}
2011-01-07 06:50:29 +00:00
else if ( retval = = BKE_READ_EXOTIC_FAIL_FORMAT ) {
2011-10-20 20:38:26 +00:00
BKE_reportf ( reports , RPT_ERROR , IFACE_ ( " File format is not supported in file: \" %s \" . " ) , filepath ) ;
2011-01-07 06:50:29 +00:00
}
else if ( retval = = BKE_READ_EXOTIC_FAIL_PATH ) {
2011-10-20 20:38:26 +00:00
BKE_reportf ( reports , RPT_ERROR , IFACE_ ( " File path invalid: \" %s \" . " ) , filepath ) ;
2011-01-07 06:50:29 +00:00
}
else {
2011-10-20 20:38:26 +00:00
BKE_reportf ( reports , RPT_ERROR , IFACE_ ( " Unknown error loading: \" %s \" . " ) , filepath ) ;
2011-01-09 15:12:08 +00:00
BLI_assert ( ! " invalid 'retval' " ) ;
2011-01-07 06:50:29 +00:00
}
2010-11-29 13:14:51 +00:00
WM_cursor_wait ( 0 ) ;
2002-10-12 11:37:38 +00:00
}
2006-07-04 12:10:37 +00:00
2007-12-24 18:27:28 +00:00
/* called on startup, (context entirely filled with NULLs) */
2009-09-11 12:05:09 +00:00
/* or called for 'New File' */
2.5
Summary of ain features:
- Themes and Styles are now editable.
- CTRL+U "Save user defaults" now goes to new .B25.blend, so you
can use 2.4x and 2.5x next to each other. If B25 doesn't exist, it
reads the regular .B.blend
- Press Tkey in 3d window for (unfinished) toolbar WIP. It now only
shows the last operator, if appropriate.
Nkey properties moved to the other side.
A lot of work was done on removing old themes for good and properly
getting it work with the 2.5 region system. Here's some notes;
- Buttons now all have a complete set of colors, based on button classifications
(See outliner -> user prefs -> Interface
- Theme colors have been extended with basic colors for region types.
Currently colors are defined for Window, Header, List/Channels and
for Button/Tool views.
The screen manager handles this btw, so a TH_BACK will always pick the
right backdrop color.
- Menu backdrops are in in Button theme colors. Floating Panels will be in
the per-space type Themes.
- Styles were added in RNA too, but only for the font settings now.
Only Panel font, widget font and widget-label work now. The 'group label'
will be for templates mostly.
Style settings will be expanded with spacing defaults, label conventions,
etc.
- Label text colors are stored in per-space Theme too, to make sure they fit.
Same goes for Panel title color.
Note that 'shadow' for fonts can conflict with text colors; shadow color is
currently stored in Style... shadow code needs a bit of work still.
2009-04-27 13:44:11 +00:00
/* op can be NULL */
2011-09-15 13:20:18 +00:00
int WM_read_homefile ( bContext * C , ReportList * UNUSED ( reports ) , short from_memory )
2002-10-12 11:37:38 +00:00
{
2011-09-15 13:20:18 +00:00
ListBase wmbase ;
2010-10-18 06:41:16 +00:00
char tstr [ FILE_MAXDIR + FILE_MAXFILE ] ;
2010-11-10 16:49:42 +00:00
int success = 0 ;
2007-12-24 18:27:28 +00:00
free_ttfont ( ) ; /* still weird... what does it here? */
2006-07-04 12:10:37 +00:00
2006-08-20 14:41:13 +00:00
G . relbase_valid = 0 ;
2.5
Summary of ain features:
- Themes and Styles are now editable.
- CTRL+U "Save user defaults" now goes to new .B25.blend, so you
can use 2.4x and 2.5x next to each other. If B25 doesn't exist, it
reads the regular .B.blend
- Press Tkey in 3d window for (unfinished) toolbar WIP. It now only
shows the last operator, if appropriate.
Nkey properties moved to the other side.
A lot of work was done on removing old themes for good and properly
getting it work with the 2.5 region system. Here's some notes;
- Buttons now all have a complete set of colors, based on button classifications
(See outliner -> user prefs -> Interface
- Theme colors have been extended with basic colors for region types.
Currently colors are defined for Window, Header, List/Channels and
for Button/Tool views.
The screen manager handles this btw, so a TH_BACK will always pick the
right backdrop color.
- Menu backdrops are in in Button theme colors. Floating Panels will be in
the per-space type Themes.
- Styles were added in RNA too, but only for the font settings now.
Only Panel font, widget font and widget-label work now. The 'group label'
will be for templates mostly.
Style settings will be expanded with spacing defaults, label conventions,
etc.
- Label text colors are stored in per-space Theme too, to make sure they fit.
Same goes for Panel title color.
Note that 'shadow' for fonts can conflict with text colors; shadow color is
currently stored in Style... shadow code needs a bit of work still.
2009-04-27 13:44:11 +00:00
if ( ! from_memory ) {
2010-07-04 15:35:23 +00:00
char * cfgdir = BLI_get_folder ( BLENDER_USER_CONFIG , NULL ) ;
if ( cfgdir ) {
2010-10-18 06:41:16 +00:00
BLI_make_file_string ( G . main - > name , tstr , cfgdir , BLENDER_STARTUP_FILE ) ;
2010-07-04 15:35:23 +00:00
} else {
tstr [ 0 ] = ' \0 ' ;
from_memory = 1 ;
}
2.5
Summary of ain features:
- Themes and Styles are now editable.
- CTRL+U "Save user defaults" now goes to new .B25.blend, so you
can use 2.4x and 2.5x next to each other. If B25 doesn't exist, it
reads the regular .B.blend
- Press Tkey in 3d window for (unfinished) toolbar WIP. It now only
shows the last operator, if appropriate.
Nkey properties moved to the other side.
A lot of work was done on removing old themes for good and properly
getting it work with the 2.5 region system. Here's some notes;
- Buttons now all have a complete set of colors, based on button classifications
(See outliner -> user prefs -> Interface
- Theme colors have been extended with basic colors for region types.
Currently colors are defined for Window, Header, List/Channels and
for Button/Tool views.
The screen manager handles this btw, so a TH_BACK will always pick the
right backdrop color.
- Menu backdrops are in in Button theme colors. Floating Panels will be in
the per-space type Themes.
- Styles were added in RNA too, but only for the font settings now.
Only Panel font, widget font and widget-label work now. The 'group label'
will be for templates mostly.
Style settings will be expanded with spacing defaults, label conventions,
etc.
- Label text colors are stored in per-space Theme too, to make sure they fit.
Same goes for Panel title color.
Note that 'shadow' for fonts can conflict with text colors; shadow color is
currently stored in Style... shadow code needs a bit of work still.
2009-04-27 13:44:11 +00:00
}
2004-12-04 17:52:44 +00:00
/* prevent loading no UI */
G . fileflags & = ~ G_FILE_NO_UI ;
2011-11-03 03:00:45 +00:00
/* put aside screens to match with persistent windows later */
2011-09-15 13:20:18 +00:00
wm_window_match_init ( C , & wmbase ) ;
2007-12-24 18:27:28 +00:00
2007-03-02 18:15:41 +00:00
if ( ! from_memory & & BLI_exists ( tstr ) ) {
2011-01-07 06:50:29 +00:00
success = ( BKE_read_file ( C , tstr , NULL ) ! = BKE_READ_FILE_FAIL ) ;
2010-11-10 16:49:42 +00:00
if ( U . themes . first = = NULL ) {
2011-01-19 09:13:24 +00:00
printf ( " \n Error: No valid " STRINGIFY ( BLENDER_STARTUP_FILE ) " , fall back to built-in default. \n \n " ) ;
2010-11-10 16:49:42 +00:00
success = 0 ;
}
}
if ( success = = 0 ) {
2010-10-16 02:40:31 +00:00
success = BKE_read_file_from_memory ( C , datatoc_startup_blend , datatoc_startup_blend_size , NULL ) ;
2011-09-15 13:20:18 +00:00
if ( wmbase . first = = NULL ) wm_clear_default_size ( C ) ;
2011-04-28 06:20:47 +00:00
# ifdef WITH_PYTHON_SECURITY /* not default */
/* use alternative setting for security nuts
* otherwise we ' d need to patch the binary blob - startup . blend . c */
U . flag | = USER_SCRIPT_AUTOEXEC_DISABLE ;
# endif
2002-10-12 11:37:38 +00:00
}
2011-09-15 13:20:18 +00:00
2010-09-06 12:54:54 +00:00
/* prevent buggy files that had G_FILE_RELATIVE_REMAP written out by mistake. Screws up autosaves otherwise
* can remove this eventually , only in a 2.53 and older , now its not written */
G . fileflags & = ~ G_FILE_RELATIVE_REMAP ;
Code holiday commit:
- fix: user pref, window title was reset to 'Blender' on tab usage
- Undo history menu back:
- name "Undo History"
- hotkey alt+ctrl+z (alt+apple+z for mac)
- works like 2.4x, only for global undo, editmode and particle edit.
- Menu scroll
- for small windows or screens, popup menus now allow to display
all items, using internal scrolling
- works with a timer, scrolling 10 items per second when mouse
is over the top or bottom arrow
- if menu is too big to display, it now draws to top or bottom,
based on largest available space.
- also works for hotkey driven pop up menus.
- User pref "DPI" follows widget/layout size
- widgets & headers now become bigger and smaller, to match
'dpi' font sizes. Works well to match UI to monitor size.
- note that icons can get fuzzy, we need better mipmaps for it
2011-06-04 17:03:46 +00:00
/* check userdef before open window, keymaps etc */
wm_init_userdef ( C ) ;
2007-12-24 18:27:28 +00:00
/* match the read WM with current WM */
2011-09-15 13:20:18 +00:00
wm_window_match_do ( C , & wmbase ) ;
2009-11-11 04:08:09 +00:00
WM_check ( C ) ; /* opens window(s), checks keymaps */
2009-01-23 17:42:36 +00:00
2010-08-26 15:18:10 +00:00
G . main - > name [ 0 ] = ' \0 ' ;
2010-08-25 04:03:38 +00:00
2009-02-06 12:33:15 +00:00
/* When loading factory settings, the reset solid OpenGL lights need to be applied. */
2009-11-11 04:38:37 +00:00
if ( ! G . background ) GPU_default_lights ( ) ;
2009-02-06 12:33:15 +00:00
2007-12-24 18:27:28 +00:00
/* XXX */
G . save_over = 0 ; // start with save preference untitled.blend
2010-07-15 11:51:43 +00:00
G . fileflags & = ~ G_FILE_AUTOPLAY ; /* disable autoplay in startup.blend... */
2007-12-24 18:27:28 +00:00
// mainwindow_set_filename_to_title(""); // empty string re-initializes title to "Blender"
// refresh_interface_font();
// undo_editmode_clear();
Essential cleanup for mess involved with reading files, initializing UI and
patching versions for UI settings.
Currently four different levels of routines for .blend file reading exist;
/* interface level */
1) BIF_init() -> calls 3
2) BIF_read_file() -> calls 11, optional 4
3) BIF_read_homefile() -> calls 11 or 12, and then 4
4) init_userdef_file()
/* kernel level */
11) BKE_read_file() -> calls 21, and then 14
12) BKE_read_file_from_memory() -> calls 22, and then 14
13) BKE_read_file_from_memfile() -> calls 23, and then 14
14) setup_app_data()
/* loader module level */
21) BLO_read_from_file() -> calls 24
22) BLO_read_from_memory() -> calls 24
23) BLO_read_from_memfile() -> calls 24
/* loader module, internal */
24) blo_read_file_internal()
Note:
- BIF_read_homefile() has additional UI initialize calls, like windows fullscreen and executing commandline options
- Reading from memory (12) only happens for the compiled-in .B.blend
- The "memfile" here is a name I gave to the undo "file" structure. Which is constructed out of memory chunks with basic compression features.
- the kernel function setup_app_data() sets globals like "current screen" and "current scene".
So far, so good. The levels as mentioned here clearly distinguish UI from kernel, and should enable for example game loading (runtime) or background (no UI) loading. In the past years however, 'bad level' dependencies were added, and especially the patches for 'file versions' were added in too many places. The latter is evidently a result of the problem that the "UserDef" struct cannot be initialized/patched if there's not a need for a UI.
Here's how the flow goes in four different cases:
----- Starting up Blender, in foreground with UI --------------------
- creator/creator.c, main() -> calls 1
- If the commandline contains a filename, it calls 11
----- Starting up Blender, in background without UI --------------------
- creator/creator.c, main() -> calls 11 if the commandline has a filename
Note: no Userdef is read, nor initialized. Please note that this was already an existing problem for using Yafray, not setting proper file paths in background mode. The Yafray paths don't belong in the User menu.
----- Starting up Blender as a runtime executable --------------------
This only has calls to 22
----- Loading a file from within the UI (with F1, CTRL+O, using pulldowns) -----
Only calls allowed to 2. It detects if a UserDef has been read too, and in that case the init_userdef_file() will be executed.
Hope this is understandable :)
-Ton-
2004-12-08 14:12:47 +00:00
BKE_reset_undo ( ) ;
2007-12-24 18:27:28 +00:00
BKE_write_undo ( C , " original " ) ; /* save current state */
2010-04-26 10:12:03 +00:00
ED_editors_init ( C ) ;
2011-03-23 14:06:44 +00:00
DAG_on_visible_update ( CTX_data_main ( C ) , TRUE ) ;
2010-09-13 04:52:56 +00:00
2010-10-31 04:11:39 +00:00
# ifdef WITH_PYTHON
2010-09-13 04:52:56 +00:00
if ( CTX_py_init_get ( C ) ) {
/* sync addons, these may have changed from the defaults */
2011-02-22 09:14:29 +00:00
BPY_string_exec ( C , " __import__('addon_utils').reset_all() " ) ;
2010-11-27 02:39:51 +00:00
2011-01-05 02:08:54 +00:00
BPY_driver_reset ( ) ;
2011-11-03 06:53:52 +00:00
BPY_app_handlers_reset ( FALSE ) ;
2011-01-05 02:08:54 +00:00
BPY_modules_load_user ( C ) ;
2010-09-13 04:52:56 +00:00
}
# endif
2011-02-01 02:54:29 +00:00
2009-02-07 10:00:46 +00:00
WM_event_add_notifier ( C , NC_WM | ND_FILEREAD , NULL ) ;
2011-02-01 02:54:29 +00:00
/* in background mode the scene will stay NULL */
if ( ! G . background ) {
CTX_wm_window_set ( C , NULL ) ; /* exits queues */
}
2009-07-10 11:33:01 +00:00
2011-01-19 09:13:24 +00:00
return TRUE ;
2002-10-12 11:37:38 +00:00
}
2011-01-19 09:13:24 +00:00
int WM_read_homefile_exec ( bContext * C , wmOperator * op )
{
int from_memory = strcmp ( op - > type - > idname , " WM_OT_read_factory_settings " ) = = 0 ;
2011-09-15 13:20:18 +00:00
return WM_read_homefile ( C , op - > reports , from_memory ) ? OPERATOR_FINISHED : OPERATOR_CANCELLED ;
2011-01-19 09:13:24 +00:00
}
Essential cleanup for mess involved with reading files, initializing UI and
patching versions for UI settings.
Currently four different levels of routines for .blend file reading exist;
/* interface level */
1) BIF_init() -> calls 3
2) BIF_read_file() -> calls 11, optional 4
3) BIF_read_homefile() -> calls 11 or 12, and then 4
4) init_userdef_file()
/* kernel level */
11) BKE_read_file() -> calls 21, and then 14
12) BKE_read_file_from_memory() -> calls 22, and then 14
13) BKE_read_file_from_memfile() -> calls 23, and then 14
14) setup_app_data()
/* loader module level */
21) BLO_read_from_file() -> calls 24
22) BLO_read_from_memory() -> calls 24
23) BLO_read_from_memfile() -> calls 24
/* loader module, internal */
24) blo_read_file_internal()
Note:
- BIF_read_homefile() has additional UI initialize calls, like windows fullscreen and executing commandline options
- Reading from memory (12) only happens for the compiled-in .B.blend
- The "memfile" here is a name I gave to the undo "file" structure. Which is constructed out of memory chunks with basic compression features.
- the kernel function setup_app_data() sets globals like "current screen" and "current scene".
So far, so good. The levels as mentioned here clearly distinguish UI from kernel, and should enable for example game loading (runtime) or background (no UI) loading. In the past years however, 'bad level' dependencies were added, and especially the patches for 'file versions' were added in too many places. The latter is evidently a result of the problem that the "UserDef" struct cannot be initialized/patched if there's not a need for a UI.
Here's how the flow goes in four different cases:
----- Starting up Blender, in foreground with UI --------------------
- creator/creator.c, main() -> calls 1
- If the commandline contains a filename, it calls 11
----- Starting up Blender, in background without UI --------------------
- creator/creator.c, main() -> calls 11 if the commandline has a filename
Note: no Userdef is read, nor initialized. Please note that this was already an existing problem for using Yafray, not setting proper file paths in background mode. The Yafray paths don't belong in the User menu.
----- Starting up Blender as a runtime executable --------------------
This only has calls to 22
----- Loading a file from within the UI (with F1, CTRL+O, using pulldowns) -----
Only calls allowed to 2. It detects if a UserDef has been read too, and in that case the init_userdef_file() will be executed.
Hope this is understandable :)
-Ton-
2004-12-08 14:12:47 +00:00
2011-02-14 03:15:55 +00:00
void WM_read_history ( void )
2002-10-12 11:37:38 +00:00
{
2009-09-02 17:13:47 +00:00
char name [ FILE_MAX ] ;
2002-10-12 11:37:38 +00:00
LinkNode * l , * lines ;
2006-05-30 13:38:22 +00:00
struct RecentFile * recent ;
2006-05-14 19:42:48 +00:00
char * line ;
int num ;
Windows installer and Path changes, fixing various issues:
* Windows installer not working for non-admin users and multiple users
* Addon scripts not installing next to user configuration
* Portable install not being taken into account in all places
The main problem was the windows installer was installing system scripts in
AppData next to the user configuration directory, which is not shared between
users. Now these are installed in ProgramFiles, and only addon scripts added
by the users go to AppData.
On all platforms, addon scripts were sometimes getting installed between
system scripts, because the scripts folder in the executable directory was
given precedence over the user configuration folder, that is no longer done
now. So addons now behave like user configuration, they are preserved even
if you download a newer build of the same blender version.
If you have an installation of 2.57 on windows, the addon install location
will not change until we do the version bump to 2.58, to avoid conflicts with
the existing the installed 2.57 version.
The old behavior of giving precedence to the local folder was done to support
portable install, where all configuration is written to the local folder. This
is now implemented differently: if and only if a "config" folder exists in the
local folder, portable install will be assumed, and files will only be written
to that local folder.
2011-05-27 09:57:53 +00:00
char * cfgdir = BLI_get_folder ( BLENDER_USER_CONFIG , NULL ) ;
2010-07-04 15:35:23 +00:00
if ( ! cfgdir ) return ;
BLI_make_file_string ( " / " , name , cfgdir , BLENDER_HISTORY_FILE ) ;
2002-10-12 11:37:38 +00:00
2011-10-22 15:35:49 +00:00
lines = BLI_file_read_as_lines ( name ) ;
2002-10-12 11:37:38 +00:00
2006-05-30 13:38:22 +00:00
G . recent_files . first = G . recent_files . last = NULL ;
2011-11-03 03:00:45 +00:00
/* read list of recent opened files from recent-files.txt to memory */
2010-01-19 11:11:56 +00:00
for ( l = lines , num = 0 ; l & & ( num < U . recent_files ) ; l = l - > next ) {
2006-05-14 19:42:48 +00:00
line = l - > link ;
2010-01-19 11:11:56 +00:00
if ( line [ 0 ] & & BLI_exists ( line ) ) {
2006-05-30 13:38:22 +00:00
recent = ( RecentFile * ) MEM_mallocN ( sizeof ( RecentFile ) , " RecentFile " ) ;
BLI_addtail ( & ( G . recent_files ) , recent ) ;
2011-02-13 03:21:27 +00:00
recent - > filepath = BLI_strdup ( line ) ;
2010-01-19 11:11:56 +00:00
num + + ;
2006-05-14 19:42:48 +00:00
}
2002-10-12 11:37:38 +00:00
}
2006-05-15 12:18:47 +00:00
2011-10-22 15:35:49 +00:00
BLI_file_free_lines ( lines ) ;
2002-10-12 11:37:38 +00:00
}
2010-07-04 15:35:23 +00:00
static void write_history ( void )
2002-10-12 11:37:38 +00:00
{
2006-05-30 13:38:22 +00:00
struct RecentFile * recent , * next_recent ;
2002-10-12 11:37:38 +00:00
char name [ FILE_MAXDIR + FILE_MAXFILE ] ;
2010-10-20 23:13:12 +00:00
char * user_config_dir ;
2002-10-12 11:37:38 +00:00
FILE * fp ;
2006-05-30 13:38:22 +00:00
int i ;
2002-10-12 11:37:38 +00:00
2010-10-20 23:13:12 +00:00
/* will be NULL in background mode */
user_config_dir = BLI_get_folder_create ( BLENDER_USER_CONFIG , NULL ) ;
if ( ! user_config_dir )
return ;
BLI_make_file_string ( " / " , name , user_config_dir , BLENDER_HISTORY_FILE ) ;
2002-10-12 11:37:38 +00:00
2006-05-31 09:54:26 +00:00
recent = G . recent_files . first ;
2010-07-15 11:51:43 +00:00
/* refresh recent-files.txt of recent opened files, when current file was changed */
2011-04-06 06:03:48 +00:00
if ( ! ( recent ) | | ( BLI_path_cmp ( recent - > filepath , G . main - > name ) ! = 0 ) ) {
2006-05-31 09:54:26 +00:00
fp = fopen ( name , " w " ) ;
if ( fp ) {
/* add current file to the beginning of list */
recent = ( RecentFile * ) MEM_mallocN ( sizeof ( RecentFile ) , " RecentFile " ) ;
2011-02-14 01:31:44 +00:00
recent - > filepath = BLI_strdup ( G . main - > name ) ;
2006-05-31 09:54:26 +00:00
BLI_addhead ( & ( G . recent_files ) , recent ) ;
2010-07-15 11:51:43 +00:00
/* write current file to recent-files.txt */
2010-06-14 03:52:10 +00:00
fprintf ( fp , " %s \n " , recent - > filepath ) ;
2006-05-31 09:54:26 +00:00
recent = recent - > next ;
i = 1 ;
2010-07-15 11:51:43 +00:00
/* write rest of recent opened files to recent-files.txt */
2007-03-18 03:30:24 +00:00
while ( ( i < U . recent_files ) & & ( recent ) ) {
2006-05-29 15:30:43 +00:00
/* this prevents to have duplicities in list */
2011-04-06 06:03:48 +00:00
if ( BLI_path_cmp ( recent - > filepath , G . main - > name ) ! = 0 ) {
2010-06-14 03:52:10 +00:00
fprintf ( fp , " %s \n " , recent - > filepath ) ;
2006-05-30 13:38:22 +00:00
recent = recent - > next ;
2006-05-29 15:30:43 +00:00
}
2006-05-30 13:38:22 +00:00
else {
next_recent = recent - > next ;
2010-06-14 03:52:10 +00:00
MEM_freeN ( recent - > filepath ) ;
2006-05-30 13:38:22 +00:00
BLI_freelinkN ( & ( G . recent_files ) , recent ) ;
recent = next_recent ;
}
i + + ;
2006-05-29 15:30:43 +00:00
}
2006-09-16 11:58:38 +00:00
fclose ( fp ) ;
2006-05-14 19:42:48 +00:00
}
2011-01-05 14:56:10 +00:00
/* also update most recent files on System */
GHOST_addToSystemRecentFiles ( G . main - > name ) ;
2002-10-12 11:37:38 +00:00
}
}
2010-10-14 12:24:08 +00:00
static ImBuf * blend_file_thumb ( Scene * scene , int * * thumb_pt )
2010-05-24 21:52:18 +00:00
{
/* will be scaled down, but gives some nice oversampling */
ImBuf * ibuf ;
int * thumb ;
2011-03-06 23:12:12 +00:00
char err_out [ 256 ] = " unknown " ;
2010-05-24 21:52:18 +00:00
* thumb_pt = NULL ;
2011-07-04 05:23:36 +00:00
/* scene can be NULL if running a script at startup and calling the save operator */
if ( G . background | | scene = = NULL | | scene - > camera = = NULL )
2010-05-30 19:21:28 +00:00
return NULL ;
2010-05-26 10:52:39 +00:00
2010-05-24 21:52:18 +00:00
/* gets scaled to BLEN_THUMB_SIZE */
2011-04-30 05:42:37 +00:00
ibuf = ED_view3d_draw_offscreen_imbuf_simple ( scene , scene - > camera , BLEN_THUMB_SIZE * 2 , BLEN_THUMB_SIZE * 2 , IB_rect , OB_SOLID , err_out ) ;
2010-05-24 21:52:18 +00:00
if ( ibuf ) {
2010-05-30 09:16:50 +00:00
float aspect = ( scene - > r . xsch * scene - > r . xasp ) / ( scene - > r . ysch * scene - > r . yasp ) ;
2010-05-24 21:52:18 +00:00
/* dirty oversampling */
IMB_scaleImBuf ( ibuf , BLEN_THUMB_SIZE , BLEN_THUMB_SIZE ) ;
2010-06-01 13:06:13 +00:00
/* add pretty overlay */
IMB_overlayblend_thumb ( ibuf - > rect , ibuf - > x , ibuf - > y , aspect ) ;
2010-05-24 21:52:18 +00:00
/* first write into thumb buffer */
2010-05-26 10:52:39 +00:00
thumb = MEM_mallocN ( ( ( 2 + ( BLEN_THUMB_SIZE * BLEN_THUMB_SIZE ) ) ) * sizeof ( int ) , " write_file thumb " ) ;
2010-05-24 21:52:18 +00:00
thumb [ 0 ] = BLEN_THUMB_SIZE ;
thumb [ 1 ] = BLEN_THUMB_SIZE ;
2010-05-26 10:52:39 +00:00
2010-05-24 21:52:18 +00:00
memcpy ( thumb + 2 , ibuf - > rect , BLEN_THUMB_SIZE * BLEN_THUMB_SIZE * sizeof ( int ) ) ;
2010-05-26 10:52:39 +00:00
}
else {
/* '*thumb_pt' needs to stay NULL to prevent a bad thumbnail from being handled */
2011-03-06 23:12:12 +00:00
fprintf ( stderr , " blend_file_thumb failed to create thumbnail: %s \n " , err_out ) ;
2010-05-26 10:52:39 +00:00
thumb = NULL ;
2010-05-24 21:52:18 +00:00
}
/* must be freed by caller */
* thumb_pt = thumb ;
2010-05-30 19:21:28 +00:00
return ibuf ;
2010-05-24 21:52:18 +00:00
}
2010-06-22 08:38:12 +00:00
/* easy access from gdb */
int write_crash_blend ( void )
{
char path [ FILE_MAX ] ;
2011-06-02 12:44:59 +00:00
int fileflags = G . fileflags & ~ ( G_FILE_HISTORY ) ; /* don't do file history on crash file */
2010-10-18 06:41:16 +00:00
BLI_strncpy ( path , G . main - > name , sizeof ( path ) ) ;
2010-06-22 08:38:12 +00:00
BLI_replace_extension ( path , sizeof ( path ) , " _crash.blend " ) ;
2011-06-02 12:44:59 +00:00
if ( BLO_write_file ( G . main , path , fileflags , NULL , NULL ) ) {
2010-06-22 08:38:12 +00:00
printf ( " written: %s \n " , path ) ;
return 1 ;
}
else {
printf ( " failed: %s \n " , path ) ;
return 0 ;
}
}
2010-09-17 08:53:39 +00:00
int WM_write_file ( bContext * C , const char * target , int fileflags , ReportList * reports , int copy )
2002-10-12 11:37:38 +00:00
{
Library * li ;
2009-10-20 13:58:53 +00:00
int len ;
2011-05-18 06:27:32 +00:00
char filepath [ FILE_MAX ] ;
2010-05-24 21:52:18 +00:00
int * thumb = NULL ;
2010-05-30 19:21:28 +00:00
ImBuf * ibuf_thumb = NULL ;
2010-05-24 21:52:18 +00:00
2007-10-21 09:32:18 +00:00
len = strlen ( target ) ;
2010-04-16 05:24:58 +00:00
if ( len = = 0 ) {
BKE_report ( reports , RPT_ERROR , " Path is empty, cannot save " ) ;
return - 1 ;
}
2007-10-21 09:32:18 +00:00
if ( len > = FILE_MAX ) {
2008-12-29 13:38:08 +00:00
BKE_report ( reports , RPT_ERROR , " Path too long, cannot save " ) ;
2010-04-14 20:45:36 +00:00
return - 1 ;
2007-10-21 09:32:18 +00:00
}
2004-08-17 04:26:00 +00:00
2011-05-18 06:27:32 +00:00
BLI_strncpy ( filepath , target , FILE_MAX ) ;
BLI_replace_extension ( filepath , FILE_MAX , " .blend " ) ;
2010-09-17 08:53:39 +00:00
/* dont use 'target' anymore */
BPython:
- Made Blender.event var (previously only used by script links) hold ascii value -- where it applies -- of current event during events callback registered with Draw.Register(gui, events, button_events). Useful for gui scripts like Campbell's Python console. No problem using this var to hold the value, since in gui scripts it was not used (always None).
- Updated Window and Window.Theme with new theme vars and the Time space.
- Script links:
-- Added "Render" event for script links (runs twice, second time as "PostEvent", for clean-up actions). Now FrameChanged links don't run when a single pic is rendered.
-- Added "Enable Script Links" button in the script buttons tab. Now this bit gets saved in .blends along with the rest of G.f, so users can define per .blend if they are on or off by default. "blender -y" also disables all slinks as happened before with OnLoad ones only.
-- Other small changes in the script buttons tab:
When a link is added (button "new"), it becomes the active one for the window, no need to press a button to reach it.
Also, a pupmenu showing all available texts is shown when "new" is pressed, so users can choose a text w/o having to type. Cancel the popup to leave the string button empty (link exists, but has no script assigned). A pulldown would be better UI-wise, but it's kinda weird to show both scripts and normal texts (Blender doesn't differentiate them) in a script links pulldown. With a popup we can show only texts ending in ".py" (not done in this commit, need opinions) and if the script has no or another extension, case of many in old and current .blend's, there's still the string box for writing its name.
-- Implemented Ton's space handler script links:
Right now only for the 3d View, but it's trivial to add for others. There are two types: EVENT, to receive 3d View events from a chosen window and DRAW, to draw on the window. Ton's idea was to give scripts a controlled way to integrate better within Blender.
Here's how it works:
- scripts must have a proper header, like:
# SPACEHANDLER.VIEW3D.EVENT
and then they are shown in 3d View's View menu, "Space Handler Scripts" submenu. Check (mark, click on it) a script to make it active.
EVENT handlers should consult the Blender.event var to get the current event, which can be compared with values from the Draw module:
import Blender
from Blender import Draw
evt = Blender.event
if evt == Draw.AKEY:
print "a"
elif evt == Draw.LEFTMOUSE:
print "left mouse button"
else:
return # ignore, pass event back to Blender
Blender.event = None # tell Blender not to process itself the event
DRAW handlers are free to draw to their owner 3D View. OpenGL attributes and modelview and projection matrices are pushed before running the handler and poped when it finishes.
To communicate between EVENT and DRAW handler scripts we have the Blender.Registry module, as always.
Still need to code some nice example, which should also serve to test properly space handlers. Simple tests went fine.
- doc updates about the additions.
=======
Note: the UI part of the space handlers and script links is of course open for changes, I just tried to make it understandable. Probably we won't use the scriptlinks icon for "None Available" (check 3d View -> View -> Space Handler Scripts), though it hints at what space handlers are. The tooltips may not be accepted either, since other menus don't use them. Opinions welcomed.
2005-05-08 21:20:34 +00:00
/* send the OnSave event */
2002-10-12 11:37:38 +00:00
for ( li = G . main - > library . first ; li ; li = li - > id . next ) {
2011-05-18 06:27:32 +00:00
if ( BLI_path_cmp ( li - > filepath , filepath ) = = 0 ) {
2011-11-07 15:55:03 +00:00
BKE_reportf ( reports , RPT_ERROR , " Can't overwrite used library '%.240s' " , filepath ) ;
2010-04-14 20:45:36 +00:00
return - 1 ;
2002-10-12 11:37:38 +00:00
}
}
2011-06-25 15:54:20 +00:00
/* blend file thumbnail */
/* save before exit_editmode, otherwise derivedmeshes for shared data corrupt #27765) */
2011-07-13 19:16:25 +00:00
if ( U . flag & USER_SAVE_PREVIEWS ) {
ibuf_thumb = blend_file_thumb ( CTX_data_scene ( C ) , & thumb ) ;
}
2011-06-24 16:54:30 +00:00
BLI_exec_cb ( G . main , NULL , BLI_CB_EVT_SAVE_PRE ) ;
2010-09-17 08:53:39 +00:00
/* operator now handles overwrite checks */
2002-10-12 11:37:38 +00:00
if ( G . fileflags & G_AUTOPACK ) {
2009-06-30 19:20:45 +00:00
packAll ( G . main , reports ) ;
2002-10-12 11:37:38 +00:00
}
2005-07-25 10:58:21 +00:00
- add torus back from 2.4x as an operator
bpy.ops.mesh.primitive_torus_add(major_radius=1, minor_radius=0.25, major_segments=48, minor_segments=16)
- experemental dynamic menus, used for INFO_MT_file, INFO_MT_file_import, INFO_MT_file_export and INFO_MT_mesh_add. these can have items added from python.
eg.
- removed OBJECT_OT_mesh_add, use the python add menu instead.
- made mesh primitive ops - MESH_OT_primitive_plane_add, ...cube_add, etc. work in object mode.
- RNA scene.active_object wrapped
- bugfix [#19466] 2.5: Tweak menu only available for mesh objects added within Edit Mode
ED_object_exit_editmode was always doing an undo push, made this optional using the existing flag - EM_DO_UNDO, called everywhere except when adding primitives.
2009-10-10 21:23:20 +00:00
ED_object_exit_editmode ( C , EM_DO_UNDO ) ;
2009-11-25 14:27:50 +00:00
ED_sculpt_force_update ( C ) ;
2002-10-12 11:37:38 +00:00
2010-12-27 18:54:43 +00:00
/* don't forget not to return without! */
WM_cursor_wait ( 1 ) ;
2011-06-02 12:44:59 +00:00
fileflags | = G_FILE_HISTORY ; /* write file history */
2010-07-15 10:51:05 +00:00
2011-05-18 06:27:32 +00:00
if ( BLO_write_file ( CTX_data_main ( C ) , filepath , fileflags , reports , thumb ) ) {
2010-07-19 15:39:12 +00:00
if ( ! copy ) {
G . relbase_valid = 1 ;
2011-05-18 06:27:32 +00:00
BLI_strncpy ( G . main - > name , filepath , sizeof ( G . main - > name ) ) ; /* is guaranteed current file */
2010-07-19 15:39:12 +00:00
G . save_over = 1 ; /* disable untitled.blend convention */
}
2009-07-23 21:35:11 +00:00
2009-10-20 13:58:53 +00:00
if ( fileflags & G_FILE_COMPRESS ) G . fileflags | = G_FILE_COMPRESS ;
2009-07-23 21:35:11 +00:00
else G . fileflags & = ~ G_FILE_COMPRESS ;
2009-02-13 13:33:01 +00:00
2010-03-05 10:37:55 +00:00
if ( fileflags & G_FILE_AUTOPLAY ) G . fileflags | = G_FILE_AUTOPLAY ;
else G . fileflags & = ~ G_FILE_AUTOPLAY ;
2011-06-08 01:53:12 +00:00
/* prevent background mode scripts from clobbering history */
if ( ! G . background ) {
write_history ( ) ;
}
2010-05-24 21:52:18 +00:00
2011-06-24 16:54:30 +00:00
BLI_exec_cb ( G . main , NULL , BLI_CB_EVT_SAVE_POST ) ;
2010-05-30 19:21:28 +00:00
/* run this function after because the file cant be written before the blend is */
if ( ibuf_thumb ) {
2011-05-18 06:27:32 +00:00
ibuf_thumb = IMB_thumb_create ( filepath , THB_NORMAL , THB_SOURCE_BLEND , ibuf_thumb ) ;
2010-05-30 19:21:28 +00:00
IMB_freeImBuf ( ibuf_thumb ) ;
}
2010-05-24 21:52:18 +00:00
if ( thumb ) MEM_freeN ( thumb ) ;
}
else {
2010-05-30 19:21:28 +00:00
if ( ibuf_thumb ) IMB_freeImBuf ( ibuf_thumb ) ;
2010-05-24 21:52:18 +00:00
if ( thumb ) MEM_freeN ( thumb ) ;
2010-11-29 13:14:51 +00:00
WM_cursor_wait ( 0 ) ;
2010-04-14 20:45:36 +00:00
return - 1 ;
2002-10-12 11:37:38 +00:00
}
2010-11-29 13:14:51 +00:00
WM_cursor_wait ( 0 ) ;
2010-04-14 20:45:36 +00:00
return 0 ;
2002-10-12 11:37:38 +00:00
}
2007-12-24 18:27:28 +00:00
/* operator entry */
int WM_write_homefile ( bContext * C , wmOperator * op )
2002-10-12 11:37:38 +00:00
{
2009-10-20 13:58:53 +00:00
wmWindowManager * wm = CTX_wm_manager ( C ) ;
2009-07-24 12:43:59 +00:00
wmWindow * win = CTX_wm_window ( C ) ;
2011-05-18 06:27:32 +00:00
char filepath [ FILE_MAXDIR + FILE_MAXFILE ] ;
2009-10-20 13:58:53 +00:00
int fileflags ;
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
2009-07-24 12:43:59 +00:00
/* check current window and close it if temp */
2010-11-09 14:54:59 +00:00
if ( win - > screen - > temp )
2009-10-20 13:58:53 +00:00
wm_window_close ( C , wm , win ) ;
2009-07-24 12:43:59 +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
/* update keymaps in user preferences */
WM_keyconfig_update ( wm ) ;
2011-05-18 06:27:32 +00:00
BLI_make_file_string ( " / " , filepath , BLI_get_folder_create ( BLENDER_USER_CONFIG , NULL ) , BLENDER_STARTUP_FILE ) ;
printf ( " trying to save homefile at %s " , filepath ) ;
2009-07-24 12:43:59 +00:00
2004-04-20 19:12:48 +00:00
/* force save as regular blend file */
2011-06-02 12:44:59 +00:00
fileflags = G . fileflags & ~ ( G_FILE_COMPRESS | G_FILE_AUTOPLAY | G_FILE_LOCK | G_FILE_SIGN | G_FILE_HISTORY ) ;
2008-12-19 00:50:21 +00:00
2011-05-18 06:27:32 +00:00
if ( BLO_write_file ( CTX_data_main ( C ) , filepath , fileflags , op - > reports , NULL ) = = 0 ) {
2010-10-03 20:00:22 +00:00
printf ( " fail \n " ) ;
return OPERATOR_CANCELLED ;
}
2007-12-24 18:27:28 +00:00
2010-10-03 20:00:22 +00:00
printf ( " ok \n " ) ;
2009-02-18 13:29:54 +00:00
G . save_over = 0 ;
2010-10-03 20:00:22 +00:00
2008-12-08 16:43:19 +00:00
return OPERATOR_FINISHED ;
2002-10-12 11:37:38 +00:00
}
2009-10-20 13:58:53 +00:00
/************************ autosave ****************************/
2011-05-18 06:27:32 +00:00
void wm_autosave_location ( char * filepath )
2002-10-12 11:37:38 +00:00
{
2009-10-20 13:58:53 +00:00
char pidstr [ 32 ] ;
# ifdef WIN32
2010-07-15 21:39:47 +00:00
char * savedir ;
2009-10-20 13:58:53 +00:00
# endif
2011-02-12 16:54:24 +00:00
BLI_snprintf ( pidstr , sizeof ( pidstr ) , " %d.blend " , abs ( getpid ( ) ) ) ;
2009-10-20 13:58:53 +00:00
# ifdef WIN32
2010-07-17 00:38:34 +00:00
/* XXX Need to investigate how to handle default location of '/tmp/'
* This is a relative directory on Windows , and it may be
* found . Example :
* Blender installed on D : \ drive , D : \ drive has D : \ tmp \
* Now , BLI_exists ( ) will find ' / tmp / ' exists , but
* BLI_make_file_string will create string that has it most likely on C : \
* through get_default_root ( ) .
* If there is no C : \ tmp autosave fails . */
2011-10-21 17:37:38 +00:00
if ( ! BLI_exists ( BLI_temporary_dir ( ) ) ) {
2010-07-15 21:39:47 +00:00
savedir = BLI_get_folder_create ( BLENDER_USER_AUTOSAVE , NULL ) ;
2011-05-18 06:27:32 +00:00
BLI_make_file_string ( " / " , filepath , savedir , pidstr ) ;
2009-10-20 13:58:53 +00:00
return ;
}
# endif
2011-09-28 19:11:59 +00:00
2011-10-21 17:37:38 +00:00
BLI_make_file_string ( " / " , filepath , BLI_temporary_dir ( ) , pidstr ) ;
2009-10-20 13:58:53 +00:00
}
2002-10-12 11:37:38 +00:00
2009-12-08 17:23:48 +00:00
void WM_autosave_init ( wmWindowManager * wm )
2009-10-20 13:58:53 +00:00
{
wm_autosave_timer_ended ( wm ) ;
2008-12-19 00:50:21 +00:00
2009-10-20 13:58:53 +00:00
if ( U . flag & USER_AUTOSAVE )
wm - > autosavetimer = WM_event_add_timer ( wm , NULL , TIMERAUTOSAVE , U . savetime * 60.0 ) ;
2002-10-12 11:37:38 +00:00
}
2010-10-16 02:40:31 +00:00
void wm_autosave_timer ( const bContext * C , wmWindowManager * wm , wmTimer * UNUSED ( wt ) )
2002-10-12 11:37:38 +00:00
{
2009-10-20 13:58:53 +00:00
wmWindow * win ;
wmEventHandler * handler ;
2011-05-18 06:27:32 +00:00
char filepath [ FILE_MAX ] ;
2009-10-20 13:58:53 +00:00
int fileflags ;
WM_event_remove_timer ( wm , NULL , wm - > autosavetimer ) ;
/* if a modal operator is running, don't autosave, but try again in 10 seconds */
for ( win = wm - > windows . first ; win ; win = win - > next ) {
for ( handler = win - > modalhandlers . first ; handler ; handler = handler - > next ) {
if ( handler - > op ) {
wm - > autosavetimer = WM_event_add_timer ( wm , NULL , TIMERAUTOSAVE , 10.0 ) ;
return ;
}
}
}
2002-10-12 11:37:38 +00:00
2011-05-18 06:27:32 +00:00
wm_autosave_location ( filepath ) ;
2009-10-20 13:58:53 +00:00
/* force save as regular blend file */
2011-06-02 12:44:59 +00:00
fileflags = G . fileflags & ~ ( G_FILE_COMPRESS | G_FILE_AUTOPLAY | G_FILE_LOCK | G_FILE_SIGN | G_FILE_HISTORY ) ;
2009-10-20 13:58:53 +00:00
/* no error reporting to console */
2011-05-18 06:27:32 +00:00
BLO_write_file ( CTX_data_main ( C ) , filepath , fileflags , NULL , NULL ) ;
2003-11-25 17:36:37 +00:00
2009-10-20 13:58:53 +00:00
/* do timer after file write, just in case file write takes a long time */
wm - > autosavetimer = WM_event_add_timer ( wm , NULL , TIMERAUTOSAVE , U . savetime * 60.0 ) ;
}
void wm_autosave_timer_ended ( wmWindowManager * wm )
{
if ( wm - > autosavetimer ) {
WM_event_remove_timer ( wm , NULL , wm - > autosavetimer ) ;
wm - > autosavetimer = NULL ;
}
}
void wm_autosave_delete ( void )
{
char filename [ FILE_MAX ] ;
wm_autosave_location ( filename ) ;
if ( BLI_exists ( filename ) ) {
2002-10-12 11:37:38 +00:00
char str [ FILE_MAXDIR + FILE_MAXFILE ] ;
2011-10-21 17:37:38 +00:00
BLI_make_file_string ( " / " , str , BLI_temporary_dir ( ) , " quit.blend " ) ;
Another step in the undo evolution.
- Made unified API for undo calls, to be found in space.c
BIF_undo_push(char *str)
BIF_undo(void)
BIF_redo(void)
These calls will do all undo levels, including editmode and vpaint.
The transition is work in progress, because mesh undo needs recode.
- New global hotkey CTR+Z for undo
Note: 'shaded draw mode' still is SHIFT+Z, the old CTRL+Z was to recalc
the lighting in shaded mode, which already became much more interactive,
like during/after any transform().
Recalc hotkey now is SHIFT+ALT+Z
CTRL+<any modifier>+Z is redo.
- For OSX users; the Apple-key ("Command") now maps to CTRL as well. This
disables the one-mouse-button hack for rightmouse btw, will be fixed in
next commit. At least we can use Apple-Z :)
- Old Ukey for undo is still there, as a training period... my preference is
to restore Ukey to "reload original data" as in past, and only use new
CTRL+Z for undo.
- Added undo_push() for all of editobject.c and editview.c. Meaning we can
start using/testing global undo in the 3d window. Please dont comment on
missing parts for now, first I want someone to volunteer to tackle all of
that.
- Since the global undo has a full 'file' in memory, it can save extremely
fast on exit to <temp dir>/quit.blend. That's default now when global undo
is enabled. It prints "Saved session recovery to ..." in console then.
- In file menu, a new option is added "Recover Last Session". Note that this
reads the undo-save, which is without UI.
- With such nice new features we then can also kill the disputed
Cancel/Confirm menu on Q-KEY.
- Added fix which initializes seam/normal theme color on saved themes.
They showed black now.... (Note: that's in usiblender.c!)
2004-09-18 12:12:45 +00:00
2009-10-20 13:58:53 +00:00
/* if global undo; remove tempsave, otherwise rename */
if ( U . uiflag & USER_GLOBALUNDO ) BLI_delete ( filename , 0 , 0 ) ;
else BLI_rename ( filename , str ) ;
2002-10-12 11:37:38 +00:00
}
}
2009-10-20 13:58:53 +00:00
void wm_autosave_read ( bContext * C , ReportList * reports )
{
char filename [ FILE_MAX ] ;
wm_autosave_location ( filename ) ;
WM_read_file ( C , filename , reports ) ;
}
2002-10-12 11:37:38 +00:00