Merged changes in the trunk up to revision 51718.
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>
Mon, 29 Oct 2012 01:09:12 +0000 (01:09 +0000)
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>
Mon, 29 Oct 2012 01:09:12 +0000 (01:09 +0000)
Conflicts resolved:
source/blender/blenloader/intern/readfile.c
source/blender/makesrna/intern/rna_scene.c
release/datafiles/startup.blend

62 files changed:
1  2 
build_files/scons/tools/Blender.py
release/datafiles/startup.blend
release/scripts/startup/bl_ui/space_view3d.py
source/blender/blenkernel/CMakeLists.txt
source/blender/blenkernel/SConscript
source/blender/blenkernel/intern/anim_sys.c
source/blender/blenkernel/intern/group.c
source/blender/blenkernel/intern/library.c
source/blender/blenkernel/intern/material.c
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/scene.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/blenlib/intern/bpath.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/bmesh/bmesh_class.h
source/blender/bmesh/intern/bmesh_construct.c
source/blender/bmesh/operators/bmo_utils.c
source/blender/editors/animation/anim_channels_defines.c
source/blender/editors/animation/anim_channels_edit.c
source/blender/editors/animation/anim_filter.c
source/blender/editors/interface/interface_templates.c
source/blender/editors/interface/resources.c
source/blender/editors/mesh/editmesh_select.c
source/blender/editors/mesh/editmesh_tools.c
source/blender/editors/mesh/mesh_intern.h
source/blender/editors/mesh/mesh_ops.c
source/blender/editors/space_buttons/buttons_context.c
source/blender/editors/space_buttons/space_buttons.c
source/blender/editors/space_file/filelist.c
source/blender/editors/space_nla/nla_buttons.c
source/blender/editors/space_nla/nla_channels.c
source/blender/editors/space_view3d/drawobject.c
source/blender/editors/transform/transform.c
source/blender/makesdna/DNA_material_types.h
source/blender/makesdna/DNA_meshdata_types.h
source/blender/makesdna/DNA_scene_types.h
source/blender/makesdna/DNA_space_types.h
source/blender/makesdna/DNA_userdef_types.h
source/blender/makesdna/intern/makesdna.c
source/blender/makesrna/RNA_access.h
source/blender/makesrna/intern/makesrna.c
source/blender/makesrna/intern/rna_ID.c
source/blender/makesrna/intern/rna_action.c
source/blender/makesrna/intern/rna_color.c
source/blender/makesrna/intern/rna_internal.h
source/blender/makesrna/intern/rna_main_api.c
source/blender/makesrna/intern/rna_scene.c
source/blender/makesrna/intern/rna_space.c
source/blender/makesrna/intern/rna_userdef.c
source/blender/python/intern/bpy.c
source/blender/render/extern/include/RE_pipeline.h
source/blender/render/intern/include/render_types.h
source/blender/render/intern/source/convertblender.c
source/blender/render/intern/source/pipeline.c
source/blender/render/intern/source/render_result.c
source/blender/render/intern/source/shadeoutput.c
source/blender/windowmanager/WM_types.h
source/blender/windowmanager/intern/wm_files.c
source/blenderplayer/bad_level_call_stubs/stubs.c
source/creator/CMakeLists.txt
source/creator/creator.c

index 8f515f906f0ee112b60fc77dc369c4e74a617c2f,eb646f27d53d87adbcf49552a6f5736a693a6028..8443e7afb19587c7712865c19ed14c717959b7f1
@@@ -136,6 -136,11 +136,11 @@@ def setup_staticlibs(lenv)
          lenv['BF_ICONV_LIBPATH']
          ])
  
+     if lenv['WITH_BF_STATICJPEG']:
+         statlibs += Split(lenv['BF_JPEG_LIB_STATIC'])
+     if lenv['WITH_BF_STATICPNG']:
+         statlibs += Split(lenv['BF_PNG_LIB_STATIC'])
      libincs += Split(lenv['BF_FREETYPE_LIBPATH'])
      if lenv['WITH_BF_PYTHON']:
          libincs += Split(lenv['BF_PYTHON_LIBPATH'])
          libincs += Split(lenv['BF_SDL_LIBPATH'])
      if lenv['WITH_BF_JACK']:
          libincs += Split(lenv['BF_JACK_LIBPATH'])
+         if lenv['WITH_BF_STATICJACK']:
+             statlibs += Split(lenv['BF_JACK_LIB_STATIC'])
      if lenv['WITH_BF_SNDFILE']:
          libincs += Split(lenv['BF_SNDFILE_LIBPATH'])
      if lenv['WITH_BF_OPENEXR']:
          if lenv['OURPLATFORM'] not in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc', 'win64-mingw'):
              libincs += Split(lenv['BF_PCRE_LIBPATH'])
              libincs += Split(lenv['BF_EXPAT_LIBPATH'])
+         if lenv['WITH_BF_STATICOPENCOLLADA']:
+             statlibs += Split(lenv['BF_OPENCOLLADA_LIB_STATIC'])
  
      if lenv['WITH_BF_OPENMP']:
          if lenv['OURPLATFORM'] == 'linuxcross':
              libincs += Split(lenv['BF_OPENMP_LIBPATH'])
+         if lenv['WITH_BF_STATICOPENMP']:
+             statlibs += Split(lenv['BF_OPENMP_LIB_STATIC'])
              
      if lenv['WITH_BF_OIIO']:
          libincs += Split(lenv['BF_OIIO_LIBPATH'])
@@@ -246,7 -257,7 +257,7 @@@ def setup_syslibs(lenv)
      if lenv['WITH_BF_OPENAL']:
          if not lenv['WITH_BF_STATICOPENAL']:
              syslibs += Split(lenv['BF_OPENAL_LIB'])
-     if lenv['WITH_BF_OPENMP'] and lenv['CC'] != 'icc':
+     if lenv['WITH_BF_OPENMP'] and lenv['CC'] != 'icc' and not lenv['WITH_BF_STATICOPENMP']:
          if lenv['CC'] == 'cl.exe':
              syslibs += ['vcomp']
          else:
          syslibs += Split(lenv['BF_FFMPEG_LIB'])
          if lenv['WITH_BF_OGG']:
              syslibs += Split(lenv['BF_OGG_LIB'])
-     if lenv['WITH_BF_JACK']:
+     if lenv['WITH_BF_JACK'] and not lenv['WITH_BF_STATICJACK']:
          syslibs += Split(lenv['BF_JACK_LIB'])
      if lenv['WITH_BF_SNDFILE'] and not lenv['WITH_BF_STATICSNDFILE']:
          syslibs += Split(lenv['BF_SNDFILE_LIB'])
          syslibs += Split(lenv['BF_OPENGL_LIB'])
      if lenv['OURPLATFORM'] in ('win32-vc', 'win32-mingw','linuxcross', 'win64-vc', 'win64-mingw'):
          syslibs += Split(lenv['BF_PTHREADS_LIB'])
-     if lenv['WITH_BF_COLLADA']:
+     if lenv['WITH_BF_COLLADA'] and not lenv['WITH_BF_STATICOPENCOLLADA']:
          syslibs.append(lenv['BF_PCRE_LIB'])
          if lenv['BF_DEBUG'] and (lenv['OURPLATFORM'] != 'linux'):
              syslibs += [colladalib+'_d' for colladalib in Split(lenv['BF_OPENCOLLADA_LIB'])]
      if lenv['WITH_BF_BOOST'] and not lenv['WITH_BF_STATICBOOST']:
          syslibs += Split(lenv['BF_BOOST_LIB'])
  
-     syslibs += Split(lenv['BF_JPEG_LIB'])
-     syslibs += Split(lenv['BF_PNG_LIB'])
+     if not lenv['WITH_BF_STATICJPEG']:
+         syslibs += Split(lenv['BF_JPEG_LIB'])
+     if not lenv['WITH_BF_STATICPNG']:
+         syslibs += Split(lenv['BF_PNG_LIB'])
  
      syslibs += lenv['LLIBS']
  
@@@ -332,7 -346,7 +346,7 @@@ def propose_priorities()
  def creator(env):
      sources = ['creator.c']# + Blender.buildinfo(env, "dynamic") + Blender.resources
  
 -    incs = ['#/intern/guardedalloc', '#/source/blender/blenlib', '#/source/blender/blenkernel', '#/source/blender/editors/include', '#/source/blender/blenloader', '#/source/blender/imbuf', '#/source/blender/renderconverter', '#/source/blender/render/extern/include', '#/source/blender/windowmanager', '#/source/blender/makesdna', '#/source/blender/makesrna', '#/source/gameengine/BlenderRoutines', '#/extern/glew/include', '#/source/blender/gpu', env['BF_OPENGL_INC']]
 +    incs = ['#/intern/guardedalloc', '#/source/blender/blenlib', '#/source/blender/blenkernel', '#/source/blender/editors/include', '#/source/blender/blenloader', '#/source/blender/imbuf', '#/source/blender/renderconverter', '#/source/blender/render/extern/include', '#/source/blender/windowmanager', '#/source/blender/makesdna', '#/source/blender/makesrna', '#/source/gameengine/BlenderRoutines', '#/extern/glew/include', '#/source/blender/gpu', '#/source/blender/freestyle', env['BF_OPENGL_INC']]
  
      defs = []
  
index dee58249bde0d68aaba0e59114408373cafd6b63,5056246e7439390550e6274262563d01421b1e4d..f8d722a0d9143dab1c6ab3706e1ef11209007fab
Binary files differ
index 37f1afe333631b573a77193a41a6bd5c389bb449,d44213c199ac92a0de917a12f4c0fbb80339692a..65e5b529487fa1ce7da0ada8e27778fef25021b2
@@@ -1285,6 -1285,7 +1285,7 @@@ class VIEW3D_MT_sculpt(Menu)
          layout.prop(sculpt, "show_low_resolution")
          layout.prop(sculpt, "show_brush")
          layout.prop(sculpt, "use_deform_only")
+         layout.prop(sculpt, "show_diffuse_color")
  
  
  class VIEW3D_MT_hide_mask(Menu):
@@@ -1710,6 -1711,7 +1711,7 @@@ class VIEW3D_MT_edit_mesh_specials(Menu
          layout.operator("mesh.select_all", text="Select Inverse").action = 'INVERT'
          layout.operator("mesh.flip_normals")
          layout.operator("mesh.vertices_smooth", text="Smooth")
+         layout.operator("mesh.vertices_smooth_laplacian", text="Laplacian Smooth")
          layout.operator("mesh.inset")
          layout.operator("mesh.bevel", text="Bevel")
          layout.operator("mesh.bridge_edge_loops")
@@@ -1840,11 -1842,6 +1842,11 @@@ class VIEW3D_MT_edit_mesh_edges(Menu)
  
          layout.separator()
  
 +        layout.operator("mesh.mark_freestyle_edge").clear = False
 +        layout.operator("mesh.mark_freestyle_edge", text="Clear Freestyle Edge").clear = True
 +
 +        layout.separator()
 +
          layout.operator("mesh.edge_rotate", text="Rotate Edge CW").direction = 'CW'
          layout.operator("mesh.edge_rotate", text="Rotate Edge CCW").direction = 'CCW'
  
@@@ -1885,11 -1882,6 +1887,11 @@@ class VIEW3D_MT_edit_mesh_faces(Menu)
  
          layout.separator()
  
 +        layout.operator("mesh.mark_freestyle_face").clear = False
 +        layout.operator("mesh.mark_freestyle_face", text="Clear Freestyle Face").clear = True
 +
 +        layout.separator()
 +
          layout.operator("mesh.quads_convert_to_tris")
          layout.operator("mesh.tris_convert_to_quads")
  
@@@ -2497,8 -2489,6 +2499,8 @@@ class VIEW3D_PT_view3d_meshdisplay(Pane
          col.prop(mesh, "show_edge_bevel_weight", text="Bevel Weights")
          col.prop(mesh, "show_edge_seams", text="Seams")
          col.prop(mesh, "show_edge_sharp", text="Sharp")
 +        col.prop(mesh, "show_freestyle_edge_marks", text="Freestyle Edge Marks")
 +        col.prop(mesh, "show_freestyle_face_marks", text="Freestyle Face Marks")
  
          col.separator()
          col.label(text="Normals:")
index f690c9dcda4a32ae55ee22756704d1f0631c3707,c5dc7da8edf2b8648e09e734abd7d25d51103ea6..11ff3930ffbf7b2b6c5fa044bfa81af2f776178b
@@@ -28,7 -28,6 +28,7 @@@ set(IN
        ../blenfont
        ../blenlib
        ../blenloader
 +      ../freestyle
        ../gpu
        ../ikplugin
        ../imbuf
@@@ -102,8 -101,8 +102,8 @@@ set(SR
        intern/lamp.c
        intern/lattice.c
        intern/library.c
 -      intern/mask_evaluate.c
 -      intern/mask_rasterize.c
 +      intern/linestyle.c
 +      intern/mask_evaluate.c  intern/mask_rasterize.c
        intern/mask.c
        intern/material.c
        intern/mball.c
        BKE_lamp.h
        BKE_lattice.h
        BKE_library.h
 +      BKE_linestyle.h
        BKE_main.h
        BKE_mask.h
        BKE_material.h
@@@ -358,12 -356,6 +358,6 @@@ if(WITH_MOD_OCEANSIM
        add_definitions(-DWITH_OCEANSIM)
  endif()
  
- if(WITH_MOD_DECIMATE)
-       list(APPEND INC
-               ../../../intern/decimation/extern
-       )
- endif()
  if(WITH_MOD_BOOLEAN)
        list(APPEND INC
                ../../../intern/bsp/extern
index 8a656c735f6436491f4016f17a0f88eb95dca62f,f7b8f59fa57cdf256eae82c5a69cbfa49ff824cc..155d4068c9ad598bf0491de2caf073eb207dfd5d
@@@ -10,9 -10,9 +10,9 @@@ sources_mask = env.Glob('intern/mask*.c
  
  incs = '. #/intern/guardedalloc #/intern/memutil'
  incs += ' ../blenlib ../blenfont ../makesdna ../windowmanager'
- incs += ' ../render/extern/include #/intern/decimation/extern ../makesrna'
+ incs += ' ../render/extern/include ../makesrna'
  incs += ' ../imbuf ../ikplugin ../avi #/intern/elbeem/extern ../nodes ../modifiers'
 -incs += ' #/intern/iksolver/extern ../blenloader'
 +incs += ' #/intern/iksolver/extern ../blenloader ../freestyle'
  incs += ' #/extern/bullet2/src'
  incs += ' #/intern/opennl/extern #/intern/bsp/extern'
  incs += ' ../gpu #/extern/glew/include'
index d685edfcda2baf5880d9b8ee6d1204e9dbeca299,66ed31c5b7252e7656f67245f95f934222763b2e..d3b7b3852fc5b743433c40622be28b094cbd9b52
@@@ -86,7 -86,6 +86,7 @@@ short id_type_can_have_animdata(ID *id
                case ID_PA:
                case ID_MA: case ID_TE: case ID_NT:
                case ID_LA: case ID_CA: case ID_WO:
 +              case ID_LS:
                case ID_SPK:
                case ID_SCE:
                case ID_MC:
@@@ -189,9 -188,9 +189,9 @@@ short BKE_animdata_set_action(ReportLis
                else {
                        /* cannot set */
                        BKE_reportf(reports, RPT_ERROR,
-                                   "Couldn't set Action '%s' onto ID '%s', as it doesn't have suitably rooted paths for this purpose",
-                                   act->id.name + 2, id->name);
-                       //ok = 0;
+                                   "Could not set action '%s' onto ID '%s', as it does not have suitably rooted paths "
+                                   "for this purpose", act->id.name + 2, id->name);
+                       /* ok = 0; */
                }
        }
        else {
@@@ -420,7 -419,7 +420,7 @@@ void action_move_fcurves_by_basepath(bA
                /* should F-Curve be moved over?
                 *      - we only need the start of the path to match basepath
                 */
-               if (animpath_matches_basepath(fcu->rna_path, basepath)) {                       
+               if (animpath_matches_basepath(fcu->rna_path, basepath)) {
                        bActionGroup *agrp = NULL;
                        
                        /* if grouped... */
@@@ -575,7 -574,7 +575,7 @@@ static char *rna_path_rename_fix(ID *ow
         */
        if ( (prefixPtr && oldNamePtr) && (prefixPtr + prefixLen == oldNamePtr) ) {
                /* if we haven't aren't able to resolve the path now, try again after fixing it */
-               if (!verify_paths || check_rna_path_is_valid(owner_id, oldpath) == 0) {         
+               if (!verify_paths || check_rna_path_is_valid(owner_id, oldpath) == 0) {
                        DynStr *ds = BLI_dynstr_new();
                        char *postfixPtr = oldNamePtr + oldNameLen;
                        char *newPath = NULL;
@@@ -725,7 -724,7 +725,7 @@@ void BKE_animdata_fix_paths_rename(ID *
                /* pad the names with [" "] so that only exact matches are made */
                oldN = BLI_sprintfN("[\"%s\"]", oldName);
                newN = BLI_sprintfN("[\"%s\"]", newName);
-       } 
+       }
        else {
                oldN = BLI_sprintfN("[%d]", oldSubscript);
                newN = BLI_sprintfN("[%d]", newSubscript);
@@@ -762,7 -761,7 +762,7 @@@ void BKE_animdata_main_cb(Main *mainptr
                AnimData *adt = BKE_animdata_from_id(id); \
                if (adt) func(id, adt, user_data); \
        } (void)0
 -      
 +
        /* "embedded" nodetree cases (i.e. scene/material/texture->nodetree) */
  #define ANIMDATA_NODETREE_IDS_CB(first, NtId_Type) \
        for (id = first; id; id = id->next) { \
                } \
                if (adt) func(id, adt, user_data); \
        } (void)0
 -      
 +
        /* nodes */
        ANIMDATA_IDS_CB(mainptr->nodetree.first);
 -      
 +              
        /* textures */
        ANIMDATA_NODETREE_IDS_CB(mainptr->tex.first, Tex);
 -      
 +              
        /* lamps */
        ANIMDATA_IDS_CB(mainptr->lamp.first);
        
  
        /* scenes */
        ANIMDATA_NODETREE_IDS_CB(mainptr->scene.first, Scene);
 -}
 +      
 +      /* line styles */
 +      ANIMDATA_IDS_CB(mainptr->linestyle.first);
 +      }
  
  /* Fix all RNA-Paths throughout the database (directly access the Global.main version)
   * NOTE: it is assumed that the structure we're replacing is <prefix><["><name><"]>
@@@ -916,13 -912,10 +916,13 @@@ void BKE_all_animdata_fix_paths_rename(
        /* worlds */
        RENAMEFIX_ANIM_IDS(mainptr->world.first);
        
 +      /* linestyles */
 +      RENAMEFIX_ANIM_IDS(mainptr->linestyle.first);
 +      
        /* scenes */
        RENAMEFIX_ANIM_NODETREE_IDS(mainptr->scene.first, Scene);
 -}
 -
 +              }
 +              
  /* *********************************** */ 
  /* KeyingSet API */
  
@@@ -1246,7 -1239,7 +1246,7 @@@ static short animsys_write_rna_setting(
                                if (new_ptr.type == &RNA_PoseBone) {
                                        /* bone transforms - update pose (i.e. tag depsgraph) */
                                        skip_updates_hack = 1;
-                               }                               
+                               }
                                
                                if (skip_updates_hack == 0)
                                        RNA_property_update_cache_add(&new_ptr, prop);
@@@ -2405,9 -2398,6 +2405,9 @@@ void BKE_animsys_evaluate_all_animation
        /* movie clips */
        EVAL_ANIM_IDS(main->movieclip.first, ADT_RECALC_ANIM);
  
 +      /* linestyles */
 +      EVAL_ANIM_IDS(main->linestyle.first, ADT_RECALC_ANIM);
 +      
        /* objects */
        /* ADT_RECALC_ANIM doesn't need to be supplied here, since object AnimData gets
         * this tagged by Depsgraph on framechange. This optimization means that objects
index 3392f6f109bd044c3d04d283666ef8f908723d33,20d874e7243b1577fb9eea2d93006de089f46006..d3545cd2720a60fa3556356831d93052bff47294
@@@ -79,7 -79,6 +79,7 @@@ void BKE_group_unlink(Group *group
        Object *ob;
        Scene *sce;
        SceneRenderLayer *srl;
 +      FreestyleLineSet *lineset;
        ParticleSystem *psys;
        
        for (ma = bmain->mat.first; ma; ma = ma->id.next) {
                                base->object->flag &= ~OB_FROMGROUP;
                                base->flag &= ~OB_FROMGROUP;
                        }
-               }                       
+               }
                
                for (srl = sce->r.layers.first; srl; srl = srl->next) {
                        if (srl->light_override == group)
                                srl->light_override = NULL;
 +
 +                      for(lineset= srl->freestyleConfig.linesets.first; lineset; lineset= lineset->next) {
 +                              if (lineset->group == group)
 +                                      lineset->group= NULL;
 +                      }
                }
        }
        
index f6e86bdbb5af191c4802f7263019958e1b56942f,942e71b50522d43ac3027acc4995c741af096b16..7a33d94b3dce095f03cde41ab455de48461b0f3e
  #include "BKE_speaker.h"
  #include "BKE_movieclip.h"
  #include "BKE_mask.h"
 +#include "BKE_linestyle.h"
  
  #include "RNA_access.h"
  
@@@ -269,8 -268,6 +269,8 @@@ int id_make_local(ID *id, int test
                        return 0; /* can't be linked */
                case ID_GD:
                        return 0; /* not implemented */
 +              case ID_LS:
 +                      return 0; /* not implemented */
        }
  
        return 0;
@@@ -365,9 -362,6 +365,9 @@@ int id_copy(ID *id, ID **newid, int tes
                case ID_MSK:
                        if (!test) *newid = (ID *)BKE_mask_copy((Mask *)id);
                        return 1;
 +              case ID_LS:
 +                      if(!test) *newid= (ID*)FRS_copy_linestyle((FreestyleLineStyle*)id);
 +                      return 1;
        }
        
        return 0;
@@@ -498,8 -492,6 +498,8 @@@ ListBase *which_libbase(Main *mainlib, 
                        return &(mainlib->movieclip);
                case ID_MSK:
                        return &(mainlib->mask);
 +              case ID_LS:
 +                      return &(mainlib->linestyle);
        }
        return NULL;
  }
@@@ -584,7 -576,6 +584,7 @@@ int set_listbasepointers(Main *main, Li
        lb[a++] = &(main->wm);
        lb[a++] = &(main->movieclip);
        lb[a++] = &(main->mask);
 +      lb[a++] = &(main->linestyle);
        
        lb[a] = NULL;
  
@@@ -699,9 -690,6 +699,9 @@@ static ID *alloc_libblock_notest(short 
                case ID_MSK:
                        id = MEM_callocN(sizeof(Mask), "Mask");
                        break;
 +              case ID_LS:
 +                      id = MEM_callocN(sizeof(FreestyleLineStyle), "Freestyle Line Style");
 +                      break;
        }
        return id;
  }
@@@ -808,6 -796,18 +808,18 @@@ static void animdata_dtar_clear_cb(ID *
        }
  }
  
+ void BKE_libblock_free_data(ID *id)
+ {
+       Main *bmain = G.main;  /* should eventually be an arg */
+       
+       if (id->properties) {
+               IDP_FreeProperty(id->properties);
+               MEM_freeN(id->properties);
+       }
+       
+       /* this ID may be a driver target! */
+       BKE_animdata_main_cb(bmain, animdata_dtar_clear_cb, (void *)id);
+ }
  
  /* used in headerbuttons.c image.c mesh.c screen.c sound.c and library.c */
  void BKE_libblock_free(ListBase *lb, void *idv)
                case ID_MSK:
                        BKE_mask_free(bmain, (Mask *)id);
                        break;
 +              case ID_LS:
 +                      FRS_free_linestyle((FreestyleLineStyle *)id);
 +                      break;
        }
  
-       if (id->properties) {
-               IDP_FreeProperty(id->properties);
-               MEM_freeN(id->properties);
-       }
        BLI_remlink(lb, id);
  
-       /* this ID may be a driver target! */
-       BKE_animdata_main_cb(bmain, animdata_dtar_clear_cb, (void *)id);
+       BKE_libblock_free_data(id);
  
        MEM_freeN(id);
  }
@@@ -1215,7 -1206,7 +1221,7 @@@ static int check_for_dupid(ListBase *lb
        char left[MAX_ID_NAME + 8], leftest[MAX_ID_NAME + 8];
  
        /* make sure input name is terminated properly */
-       /* if ( strlen(name) > MAX_ID_NAME-3 ) name[MAX_ID_NAME-3]= 0; */
+       /* if ( strlen(name) > MAX_ID_NAME-3 ) name[MAX_ID_NAME-3] = 0; */
        /* removed since this is only ever called from one place - campbell */
  
        while (1) {
@@@ -1562,7 -1553,7 +1568,7 @@@ void rename_id(ID *id, const char *name
        BLI_strncpy(id->name + 2, name, sizeof(id->name) - 2);
        lb = which_libbase(G.main, GS(id->name) );
        
-       new_id(lb, id, name);                           
+       new_id(lb, id, name);
  }
  
  void name_uiprefix_id(char *name, ID *id)
index ad28e3a6d799bfdbe2fa9507def0f9bb019e4c27,ea3179562559beea048c51c37c0169794b855c6d..445ea2d4b3b426df9bda8c614fec8a7767e1a497
@@@ -154,7 -154,6 +154,7 @@@ void init_material(Material *ma
        ma->tx_limit = 0.0;
        ma->tx_falloff = 1.0;
        ma->shad_alpha = 1.0f;
 +      ma->vcol_alpha = 0;
        
        ma->gloss_mir = ma->gloss_tra = 1.0;
        ma->samp_gloss_mir = ma->samp_gloss_tra = 18;
@@@ -216,7 -215,7 +216,7 @@@ Material *BKE_material_add(const char *
        
        init_material(ma);
        
-       return ma;      
+       return ma;
  }
  
  /* XXX keep synced with next function */
@@@ -905,7 -904,7 +905,7 @@@ short find_material_index(Object *ob, M
                        break;
        if (a < *totcolp)
                return a + 1;
-       return 0;          
+       return 0;
  }
  
  int object_add_material_slot(Object *ob)
@@@ -971,7 -970,7 +971,7 @@@ static void do_init_render_material(Mat
                ma->ambr = ma->amb * amb[0];
                ma->ambg = ma->amb * amb[1];
                ma->ambb = ma->amb * amb[2];
-       }       
+       }
        /* will become or-ed result of all node modes */
        ma->mode_l = ma->mode;
        ma->mode_l &= ~MA_SHLESS;
        if (ma->nodetree && ma->use_nodes)
                ntreeShaderGetTexcoMode(ma->nodetree, r_mode, &ma->texco, &ma->mode_l);
  
-     /* local group override */
-     if((ma->shade_flag & MA_GROUP_LOCAL) && ma->id.lib && ma->group && ma->group->id.lib) {
-         Group *group;
+       /* local group override */
+       if ((ma->shade_flag & MA_GROUP_LOCAL) && ma->id.lib && ma->group && ma->group->id.lib) {
+               Group *group;
  
-         for(group= G.main->group.first; group; group= group->id.next)
-             if(!group->id.lib && strcmp(group->id.name, ma->group->id.name) == 0)
-                 ma->group = group;
-     }
+               for (group = G.main->group.first; group; group = group->id.next) {
+                       if (!group->id.lib && strcmp(group->id.name, ma->group->id.name) == 0) {
+                               ma->group = group;
+                       }
+               }
+       }
  }
  
  static void init_render_nodetree(bNodeTree *ntree, Material *basemat, int r_mode, float *amb)
@@@ -1158,7 -1159,7 +1160,7 @@@ void material_drivers_update(Scene *sce
        
  /* ****************** */
  #if 0 /* UNUSED */
- static char colname_array[125][20]= {
+ static char colname_array[125][20] = {
  "Black", "DarkRed", "HalfRed", "Red", "Red",
  "DarkGreen", "DarkOlive", "Brown", "Chocolate", "OrangeRed",
  "HalfGreen", "GreenOlive", "DryOlive", "Goldenrod", "DarkOrange",
@@@ -1614,7 -1615,7 +1616,7 @@@ static int encode_tfaceflag(MTFace *tf
        /* calculate the flag */
        int flag = tf->mode;
  
-       /* options that change the material offline render */   
+       /* options that change the material offline render */
        if (!convertall) {
                flag &= ~TF_OBCOL;
        }
  /* set the material options based in the tface flag */
  static void decode_tfaceflag(Material *ma, int flag, int convertall)
  {
-       int alphablend; 
+       int alphablend;
        GameSettings *game = &ma->game;
  
        /* flag is shifted in 1 to make 0 != no flag yet (see encode_tfaceflag) */
@@@ -1797,13 -1798,13 +1799,13 @@@ static short convert_tfacenomaterial(Ma
                         * for now store the flag into the material and change light/tex/collision
                         * store the flag as a negative number */
                        ma->game.flag = -flag;
-                       id_us_min((ID *)ma);    
+                       id_us_min((ID *)ma);
                }
                else printf("Error: Unable to create Material \"%s\" for Mesh \"%s\".", idname + 2, me->id.name + 2);
        }
  
        /* set as converted, no need to go bad to this face */
-       tf->mode |= TF_CONVERTED;       
+       tf->mode |= TF_CONVERTED;
        return mat_nr;
  }
  
@@@ -1856,7 -1857,7 +1858,7 @@@ static void convert_tfacematerial(Main 
                                if (mat_new) {
                                        /* rename the material*/
                                        strcpy(mat_new->id.name, idname);
-                                       id_us_min((ID *)mat_new);       
+                                       id_us_min((ID *)mat_new);
  
                                        mat_nr = mesh_addmaterial(me, mat_new);
                                        decode_tfaceflag(mat_new, flag, 1);
@@@ -2044,7 -2045,7 +2046,7 @@@ int do_version_tface(Main *main, int fi
                                nowarning = 0;
                        }
                        else
-                               convert_tfacematerial(main, ma);                        continue;       
+                               convert_tfacematerial(main, ma); continue;
                }
        
                /* no conflicts in this material - 90% of cases
index ff778a4b71be05f9cbd10386035b6bead4cceb09,431f2c04f7ddd150af47c8e7d021badc5b0af548..549d4e2d12673d40fc49b35e1920a5b1e6b610ef
  
  #include "GPU_material.h"
  
 +#include "FRS_freestyle.h"
 +
  /* Local function protos */
  float originmat[3][3];  /* after BKE_object_where_is_calc(), can be used in other functions (bad!) */
  
@@@ -302,11 -300,11 +302,11 @@@ void BKE_object_free(Object *ob
        
        BKE_object_free_display(ob);
        
-       /* disconnect specific data */
+       /* disconnect specific data, but not for lib data (might be indirect data, can get relinked) */
        if (ob->data) {
                ID *id = ob->data;
                id->us--;
-               if (id->us == 0) {
+               if (id->us == 0 && id->lib==NULL) {
                        switch (ob->type) {
                                case OB_MESH:
                                        BKE_mesh_unlink((Mesh *)id);
@@@ -456,7 -454,7 +456,7 @@@ void BKE_object_unlink(Object *ob
                                if (pchan->custom == ob)
                                        pchan->custom = NULL;
                        }
-               } 
+               }
                else if (ELEM(OB_MBALL, ob->type, obt->type)) {
                        if (BKE_mball_is_basis_for(obt, ob))
                                obt->recalc |= OB_RECALC_DATA;
                                }
                                SEQ_END
                        }
 +
 +                      {
 +                              SceneRenderLayer *srl;
 +
 +                              for (srl= sce->r.layers.first; srl; srl= srl->next) {
 +                                      FRS_unlink_target_object(&srl->freestyleConfig, ob);
 +                              }
 +                      }
                }
  
                sce = sce->id.next;
@@@ -2581,9 -2571,7 +2581,7 @@@ void BKE_object_handle_update(Scene *sc
                if (ob->recalc & OB_RECALC_DATA) {
                        ID *data_id = (ID *)ob->data;
                        AnimData *adt = BKE_animdata_from_id(data_id);
-                       float ctime = (float)scene->r.cfra; // XXX this is bad...
-                       ListBase pidlist;
-                       PTCacheID *pid;
+                       float ctime = (float)scene->r.cfra;  /* XXX this is bad... */
                        
                        if (G.debug & G_DEBUG)
                                printf("recalcdata %s\n", ob->id.name + 2);
                                                psys_get_modifier(ob, psys)->flag &= ~eParticleSystemFlag_psys_updated;
                                }
                        }
-                       /* check if quick cache is needed */
-                       BKE_ptcache_ids_from_object(&pidlist, ob, scene, MAX_DUPLI_RECUR);
-                       for (pid = pidlist.first; pid; pid = pid->next) {
-                               if ((pid->cache->flag & PTCACHE_BAKED) ||
-                                   (pid->cache->flag & PTCACHE_QUICK_CACHE) == 0)
-                               {
-                                       continue;
-                               }
-                               if (pid->cache->flag & PTCACHE_OUTDATED || (pid->cache->flag & PTCACHE_SIMULATION_VALID) == 0) {
-                                       scene->physics_settings.quick_cache_step =
-                                               scene->physics_settings.quick_cache_step ?
-                                               mini(scene->physics_settings.quick_cache_step, pid->cache->step) :
-                                               pid->cache->step;
-                               }
-                       }
-                       BLI_freelistN(&pidlist);
+                       
+                       /* quick cache removed */
                }
  
                /* the no-group proxy case, we call update */
index 628a251ed262541b6ff508667d23eb8173b82af0,fbe327aa52542f1d89fc90edfc6ca91ea79ff3f8..721117d739feeddbf3b41bc5a9f17c31c4b19903
@@@ -83,8 -83,6 +83,8 @@@
  //XXX #include "BIF_previewrender.h"
  //XXX #include "BIF_editseq.h"
  
 +#include "FRS_freestyle_config.h"
 +
  #ifdef WIN32
  #else
  #include <sys/time.h>
@@@ -263,8 -261,7 +263,8 @@@ Scene *BKE_scene_copy(Scene *sce, int t
  void BKE_scene_free(Scene *sce)
  {
        Base *base;
 -
 +      SceneRenderLayer *srl;
 +      
        base = sce->base.first;
        while (base) {
                base->object->id.us--;
                sce->r.ffcodecdata.properties = NULL;
        }
        
 +      for(srl= sce->r.layers.first; srl; srl= srl->next) {
 +              FRS_free_freestyle_config(srl);
 +      }
 +      
        BLI_freelistN(&sce->markers);
        BLI_freelistN(&sce->transform_spaces);
        BLI_freelistN(&sce->r.layers);
                BKE_paint_free(&sce->toolsettings->imapaint.paint);
  
                MEM_freeN(sce->toolsettings);
-               sce->toolsettings = NULL;       
+               sce->toolsettings = NULL;
        }
        
        if (sce->theDag) {
@@@ -443,7 -436,7 +443,7 @@@ Scene *BKE_scene_add(const char *name
        sce->toolsettings->cornertype = 1;
        sce->toolsettings->degr = 90; 
        sce->toolsettings->step = 9;
-       sce->toolsettings->turn = 1;                            
+       sce->toolsettings->turn = 1;
        sce->toolsettings->extr_offs = 1; 
        sce->toolsettings->doublimit = 0.001;
        sce->toolsettings->segments = 32;
@@@ -965,7 -958,7 +965,7 @@@ float BKE_scene_frame_get_from_ctime(Sc
  {
        float ctime = frame;
        ctime += scene->r.subframe;
-       ctime *= scene->r.framelen;     
+       ctime *= scene->r.framelen;
        
        return ctime;
  }
@@@ -1049,7 -1042,7 +1049,7 @@@ void BKE_scene_update_tagged(Main *bmai
        /* flush recalc flags to dependencies */
        DAG_ids_flush_tagged(bmain);
  
-       scene->physics_settings.quick_cache_step = 0;
+       /* removed calls to quick_cache, see pointcache.c */
        
        /* clear "LIB_DOIT" flag from all materials, to prevent infinite recursion problems later 
         * when trying to find materials with drivers that need evaluating [#32017] 
                        BKE_animsys_evaluate_animdata(scene, &scene->id, adt, ctime, 0);
        }
        
-       /* quick point cache updates */
-       if (scene->physics_settings.quick_cache_step)
-               BKE_ptcache_quick_cache_all(bmain, scene);
        /* notify editors and python about recalc */
        BLI_callback_exec(bmain, &scene->id, BLI_CB_EVT_SCENE_UPDATE_POST);
        DAG_ids_check_recalc(bmain, scene, FALSE);
@@@ -1124,6 -1113,11 +1120,11 @@@ void BKE_scene_update_for_newframe(Mai
        BKE_animsys_evaluate_all_animation(bmain, sce, ctime);
        /*...done with recusrive funcs */
  
+       /* clear "LIB_DOIT" flag from all materials, to prevent infinite recursion problems later 
+        * when trying to find materials with drivers that need evaluating [#32017] 
+        */
+       tag_main_idcode(bmain, ID_MA, FALSE);
        /* BKE_object_handle_update() on all objects, groups and sets */
        scene_update_tagged_recursive(bmain, sce, sce);
  
@@@ -1154,7 -1148,6 +1155,7 @@@ SceneRenderLayer *BKE_scene_add_render_
        srl->lay = (1 << 20) - 1;
        srl->layflag = 0x7FFF;   /* solid ztra halo edge strand */
        srl->passflag = SCE_PASS_COMBINED | SCE_PASS_Z;
 +      FRS_add_freestyle_config( srl );
  
        return srl;
  }
@@@ -1201,7 -1194,7 +1202,7 @@@ int BKE_scene_remove_render_layer(Main 
  int get_render_subsurf_level(RenderData *r, int lvl)
  {
        if (r->mode & R_SIMPLIFY)
-               return MIN2(r->simplify_subsurf, lvl);
+               return min_ii(r->simplify_subsurf, lvl);
        else
                return lvl;
  }
@@@ -1217,7 -1210,7 +1218,7 @@@ int get_render_child_particle_number(Re
  int get_render_shadow_samples(RenderData *r, int samples)
  {
        if ((r->mode & R_SIMPLIFY) && samples > 0)
-               return MIN2(r->simplify_shadowsamples, samples);
+               return min_ii(r->simplify_shadowsamples, samples);
        else
                return samples;
  }
index facf0793f870fe3011533ba36f491dbb9740cf7b,6f3063ce8e381069844aa264cd84150fc87cd678..33350a80928014c1cc00abc6e99fbfd9fd3266de
@@@ -964,7 -964,7 +964,7 @@@ static void ccgDM_getFinalEdge(DerivedM
  
                edgeFlag = (ccgdm->edgeFlags) ? &ccgdm->edgeFlags[i] : NULL;
                if (edgeFlag)
 -                      flags |= (*edgeFlag & (ME_SEAM | ME_SHARP)) | ME_EDGEDRAW | ME_EDGERENDER;
 +                      flags |= (*edgeFlag & (ME_SEAM | ME_SHARP | ME_FREESTYLE_EDGE)) | ME_EDGEDRAW | ME_EDGERENDER;
                else
                        flags |= ME_EDGEDRAW | ME_EDGERENDER;
  
@@@ -1228,7 -1228,7 +1228,7 @@@ static void ccgDM_copyFinalEdgeArray(De
  
                if (edgeFlags) {
                        if (edgeIdx != -1) {
 -                              flags |= ((edgeFlags[index] & (ME_SEAM | ME_SHARP)) | ME_EDGEDRAW | ME_EDGERENDER);
 +                              flags |= ((edgeFlags[index] & (ME_SEAM | ME_SHARP | ME_FREESTYLE_EDGE)) | ME_EDGEDRAW | ME_EDGERENDER);
                        }
                }
                else {
@@@ -3020,6 -3020,9 +3020,9 @@@ static struct PBVH *ccgDM_getPBVH(Objec
                                    me->totface, me->totvert, &me->vdata);
        }
  
+       if (ccgdm->pbvh)
+               pbvh_show_diffuse_color_set(ccgdm->pbvh, ob->sculpt->show_diffuse_color);
        return ccgdm->pbvh;
  }
  
index bdcb3cb9806f37c4ac8d077a71d1fcc954b278d9,8ae2b941fa858d074233be5f996885e71e02ca1c..2f335b557fe33d63a709261bed2d0a3735c787ac
@@@ -68,7 -68,6 +68,7 @@@
  #include "DNA_vfont_types.h"
  #include "DNA_scene_types.h"
  #include "DNA_smoke_types.h"
 +#include "DNA_freestyle_types.h"
  
  #include "BLI_blenlib.h"
  #include "BLI_bpath.h"
@@@ -86,7 -85,7 +86,7 @@@ static int checkMissingFiles_visit_cb(v
        ReportList *reports = (ReportList *)userdata;
  
        if (!BLI_exists(path_src)) {
-               BKE_reportf(reports, RPT_WARNING, "Path Not Found \"%s\"", path_src);
+               BKE_reportf(reports, RPT_WARNING, "Path '%s' not found", path_src);
        }
  
        return FALSE;
@@@ -123,7 -122,7 +123,7 @@@ static int makeFilesRelative_visit_cb(v
                        data->count_changed++;
                }
                else {
-                       BKE_reportf(data->reports, RPT_WARNING, "Path cant be made relative \"%s\"", path_src);
+                       BKE_reportf(data->reports, RPT_WARNING, "Path '%s' cannot be made relative", path_src);
                        data->count_failed++;
                }
                return TRUE;
@@@ -145,7 -144,7 +145,7 @@@ void BLI_bpath_relative_convert(Main *b
        BLI_bpath_traverse_main(bmain, makeFilesRelative_visit_cb, 0, (void *)&data);
  
        BKE_reportf(reports, data.count_failed ? RPT_WARNING : RPT_INFO,
-                   "Total files %d|Changed %d|Failed %d",
+                   "Total files %d | Changed %d | Failed %d",
                    data.count_tot, data.count_changed, data.count_failed);
  }
  
@@@ -165,7 -164,7 +165,7 @@@ static int makeFilesAbsolute_visit_cb(v
                        data->count_changed++;
                }
                else {
-                       BKE_reportf(data->reports, RPT_WARNING, "Path cant be made absolute \"%s\"", path_src);
+                       BKE_reportf(data->reports, RPT_WARNING, "Path '%s' cannot be made absolute", path_src);
                        data->count_failed++;
                }
                return TRUE;
@@@ -188,13 -187,13 +188,13 @@@ void BLI_bpath_absolute_convert(Main *b
        BLI_bpath_traverse_main(bmain, makeFilesAbsolute_visit_cb, 0, (void *)&data);
  
        BKE_reportf(reports, data.count_failed ? RPT_WARNING : RPT_INFO,
-                   "Total files %d|Changed %d|Failed %d",
+                   "Total files %d | Changed %d | Failed %d",
                    data.count_tot, data.count_changed, data.count_failed);
  }
  
  /**
   * find this file recursively, use the biggest file so thumbnails don't get used by mistake
-  * \param filename_new: the path will be copied here, caller must initialize as empyu string.
+  * \param filename_new: the path will be copied here, caller must initialize as empty string.
   * \param dirname: subdir to search
   * \param filename: set this filename
   * \param filesize: filesize for the file
@@@ -280,13 -279,13 +280,13 @@@ static int findMissingFiles_visit_cb(vo
  
        if (filesize == -1) { /* could not open dir */
                BKE_reportf(data->reports, RPT_WARNING,
-                           "Could open directory \"%s\"",
+                           "Could not open directory '%s'",
                            BLI_path_basename(data->searchdir));
                return FALSE;
        }
        else if (found == FALSE) {
                BKE_reportf(data->reports, RPT_WARNING,
-                           "Could not find \"%s\" in \"%s\"",
+                           "Could not find '%s' in '%s'",
                            BLI_path_basename((char *)path_src), data->searchdir);
                return FALSE;
        }
@@@ -505,7 -504,6 +505,7 @@@ void BLI_bpath_traverse_id(Main *bmain
                case ID_SCE:
                {
                        Scene *scene = (Scene *)id;
 +                      SceneRenderLayer *srl= scene->r.layers.first;
                        if (scene->ed) {
                                Sequence *seq;
  
                                }
                                SEQ_END
                        }
 +                      for(; srl; srl= srl->next) {
 +                              FreestyleModuleConfig* module= srl->freestyleConfig.modules.first;
 +                              for (; module; module= module->next) {
 +                                      rewrite_path_fixed(module->module_path, visit_cb, absbase, bpath_user_data);
 +                              }
 +                      }
                }
                break;
                case ID_ME:
index dc8cf3b9116711bb77837190f38fbe3a18f562c2,de9e5f5e08ea291928cf55c98b1675100131603f..8929fa3ff7ad301df803e5de985309b8d95e6833
@@@ -70,7 -70,6 +70,7 @@@
  #include "DNA_key_types.h"
  #include "DNA_lattice_types.h"
  #include "DNA_lamp_types.h"
 +#include "DNA_linestyle_types.h"
  #include "DNA_meta_types.h"
  #include "DNA_material_types.h"
  #include "DNA_mesh_types.h"
@@@ -819,7 -818,7 +819,7 @@@ static void decode_blender_header(FileD
                        /* is the file saved in a different endian
                         * than we need ?
                         */
 -                      if (((((char *)&remove_this_endian_test)[0] == 1) ? L_ENDIAN : B_ENDIAN) != ((header[8] == 'v') ? L_ENDIAN : B_ENDIAN)) {
 +                      if (((((char*)&remove_this_endian_test)[0]==1)?L_ENDIAN:B_ENDIAN) != ((header[8]=='v')?L_ENDIAN:B_ENDIAN)) {
                                fd->flags |= FD_FLAGS_SWITCH_ENDIAN;
                        }
                        
@@@ -941,7 -940,7 +941,7 @@@ static int fd_read_from_memfile(FileDat
                        if (chunkoffset+readsize > chunk->size)
                                readsize= chunk->size-chunkoffset;
                        
 -                      memcpy((char *)buffer + totread, chunk->buf + chunkoffset, readsize);
 +                      memcpy((char*)buffer + totread, chunk->buf + chunkoffset, readsize);
                        totread += readsize;
                        filedata->seek += readsize;
                        seek += readsize;
@@@ -983,7 -982,7 +983,7 @@@ static FileData *blo_decode_and_check(F
                        blo_freefiledata(fd);
                        fd = NULL;
                }
 -      }
 +      } 
        else {
                BKE_reportf(reports, RPT_ERROR, "Failed to read blend file '%s', not a blend file", fd->relabase);
                blo_freefiledata(fd);
@@@ -1003,7 -1002,7 +1003,7 @@@ FileData *blo_openblenderfile(const cha
        
        if (gzfile == (gzFile)Z_NULL) {
                BKE_reportf(reports, RPT_WARNING, "Unable to open '%s': %s",
-                           filepath, errno ? strerror(errno) : TIP_("Unknown error reading file"));
+                           filepath, errno ? strerror(errno) : TIP_("unknown error reading file"));
                return NULL;
        }
        else {
@@@ -1130,7 -1129,7 +1130,7 @@@ int BLO_is_a_library(const char *path, 
                /* the last part of the dir is a .blend file, no group follows */
                *fd = '/'; /* put back the removed slash separating the dir and the .blend file name */
        }
 -      else {
 +      else {          
                char *gp = fd + 1; // in case we have a .blend file, gp points to the group
                
                /* Find the last slash */
@@@ -1294,6 -1293,7 +1294,7 @@@ void blo_end_image_pointer_map(FileDat
                        if (NULL == newimaadr(fd, ibuf)) {      /* so was restored */
                                BLI_remlink(&ima->ibufs, ibuf);
                                ima->bindcode = 0;
+                               ima->tpageflag &= ~IMA_GLBIND_IS_DATA;
                                ima->gputexture = NULL;
                        }
                }
@@@ -1632,6 -1632,19 +1633,19 @@@ static void IDP_LibLinkProperty(IDPrope
  {
  }
  
+ /* ************ READ ID *************** */
+ static void direct_link_id(FileData *fd, ID *id)
+ {
+       /*link direct data of ID properties*/
+       if (id->properties) {
+               id->properties = newdataadr(fd, id->properties);
+               if (id->properties) { /* this case means the data was written incorrectly, it should not happen */
+                       IDP_DirectLinkProperty(id->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
+               }
+       }
+ }
  /* ************ READ CurveMapping *************** */
  
  /* cuma itself has been read! */
@@@ -1825,7 -1838,7 +1839,7 @@@ static void lib_link_fcurves(FileData *
                        
                        for (dvar= driver->variables.first; dvar; dvar= dvar->next) {
                                DRIVER_TARGETS_LOOPER(dvar)
 -                              {
 +                              {       
                                        /* only relink if still used */
                                        if (tarIndex < dvar->num_targets)
                                                dtar->id = newlibadr(fd, id->lib, dtar->id); 
@@@ -2400,6 -2413,14 +2414,14 @@@ static void direct_link_nodetree(FileDa
                link_list(fd, &node->inputs);
                link_list(fd, &node->outputs);
                
+               link_list(fd, &node->internal_links);
+               for (link = node->internal_links.first; link; link = link->next) {
+                       link->fromnode = newdataadr(fd, link->fromnode);
+                       link->fromsock = newdataadr(fd, link->fromsock);
+                       link->tonode = newdataadr(fd, link->tonode);
+                       link->tosock = newdataadr(fd, link->tosock);
+               }
+               
                if (node->type == CMP_NODE_MOVIEDISTORTION) {
                        node->storage = newmclipadr(fd, node->storage);
                }
@@@ -2531,8 -2552,13 +2553,13 @@@ static void direct_link_constraints(Fil
                                break;
                        case CONSTRAINT_TYPE_KINEMATIC:
                        {
+                               bKinematicConstraint *data = con->data;
                                con->lin_error = 0.f;
                                con->rot_error = 0.f;
+                               /* version patch for runtime flag, was not cleared in some case */
+                               data->flag &= ~CONSTRAINT_IK_AUTO;
                        }
                        case CONSTRAINT_TYPE_CHILDOF:
                        {
@@@ -2713,8 -2739,10 +2740,10 @@@ static void direct_link_lamp(FileData *
                direct_link_curvemapping(fd, la->curfalloff);
  
        la->nodetree= newdataadr(fd, la->nodetree);
-       if (la->nodetree)
+       if (la->nodetree) {
+               direct_link_id(fd, &la->nodetree->id);
                direct_link_nodetree(fd, la->nodetree);
+       }
        
        la->preview = direct_link_preview_image(fd, la->preview);
  }
@@@ -2777,7 -2805,7 +2806,7 @@@ static void switch_endian_keyblock(Key 
                        
                        cp += 2;
                }
 -              data += elemsize;
 +              data+= elemsize;
        }
  }
  
@@@ -2812,7 -2840,7 +2841,7 @@@ static void lib_link_mball(FileData *fd
                        if (mb->adt) lib_link_animdata(fd, &mb->id, mb->adt);
                        
                        for (a = 0; a < mb->totcol; a++) 
 -                              mb->mat[a] = newlibadr_us(fd, mb->id.lib, mb->mat[a]);
 +                              mb->mat[a]= newlibadr_us(fd, mb->id.lib, mb->mat[a]);
                        
                        mb->ipo = newlibadr_us(fd, mb->id.lib, mb->ipo); // XXX deprecated - old animation system
                        
@@@ -2880,8 -2908,10 +2909,10 @@@ static void direct_link_world(FileData 
        }
        
        wrld->nodetree = newdataadr(fd, wrld->nodetree);
-       if (wrld->nodetree)
+       if (wrld->nodetree) {
+               direct_link_id(fd, &wrld->nodetree->id);
                direct_link_nodetree(fd, wrld->nodetree);
+       }
        
        wrld->preview = direct_link_preview_image(fd, wrld->preview);
  }
@@@ -3004,6 -3034,7 +3035,7 @@@ static void direct_link_image(FileData 
        /* if not restored, we keep the binded opengl index */
        if (ima->ibufs.first == NULL) {
                ima->bindcode = 0;
+               ima->tpageflag &= ~IMA_GLBIND_IS_DATA;
                ima->gputexture = NULL;
        }
        
@@@ -3047,7 -3078,7 +3079,7 @@@ static void lib_link_curve(FileData *fd
                        cu->taperobj = newlibadr(fd, cu->id.lib, cu->taperobj);
                        cu->textoncurve = newlibadr(fd, cu->id.lib, cu->textoncurve);
                        cu->vfont = newlibadr_us(fd, cu->id.lib, cu->vfont);
 -                      cu->vfontb = newlibadr_us(fd, cu->id.lib, cu->vfontb);
 +                      cu->vfontb = newlibadr_us(fd, cu->id.lib, cu->vfontb);                  
                        cu->vfonti = newlibadr_us(fd, cu->id.lib, cu->vfonti);
                        cu->vfontbi = newlibadr_us(fd, cu->id.lib, cu->vfontbi);
                        
@@@ -3081,7 -3112,7 +3113,7 @@@ static void direct_link_curve(FileData 
        cu->mat = newdataadr(fd, cu->mat);
        test_pointer_array(fd, (void **)&cu->mat);
        cu->str = newdataadr(fd, cu->str);
 -      cu->strinfo= newdataadr(fd, cu->strinfo);
 +      cu->strinfo= newdataadr(fd, cu->strinfo);       
        cu->tb = newdataadr(fd, cu->tb);
  
        if (cu->vfont == NULL) link_list(fd, &(cu->nurb));
                if (cu->tb) {
                        memcpy(tb, cu->tb, cu->totbox*sizeof(TextBox));
                        MEM_freeN(cu->tb);
 -                      cu->tb = tb;
 +                      cu->tb = tb;                    
                }
                else {
                        cu->totbox = 1;
                        cu->actbox = 1;
                        cu->tb = tb;
                        cu->tb[0].w = cu->linewidth;
 -              }
 +              }               
                if (cu->wordspace == 0.0f) cu->wordspace = 1.0f;
        }
  
@@@ -3188,8 -3219,10 +3220,10 @@@ static void direct_link_texture(FileDat
        tex->ot = newdataadr(fd, tex->ot);
        
        tex->nodetree = newdataadr(fd, tex->nodetree);
-       if (tex->nodetree)
+       if (tex->nodetree) {
+               direct_link_id(fd, &tex->nodetree->id);
                direct_link_nodetree(fd, tex->nodetree);
+       }
        
        tex->preview = direct_link_preview_image(fd, tex->preview);
        
@@@ -3248,8 -3281,10 +3282,10 @@@ static void direct_link_material(FileDa
        ma->ramp_spec = newdataadr(fd, ma->ramp_spec);
        
        ma->nodetree = newdataadr(fd, ma->nodetree);
-       if (ma->nodetree)
+       if (ma->nodetree) {
+               direct_link_id(fd, &ma->nodetree->id);
                direct_link_nodetree(fd, ma->nodetree);
+       }
        
        ma->preview = direct_link_preview_image(fd, ma->preview);
        ma->gpumaterial.first = ma->gpumaterial.last = NULL;
@@@ -3264,7 -3299,7 +3300,7 @@@ static const char *ptcache_data_struct[
        "", // BPHYS_DATA_ROTATION
        "", // BPHYS_DATA_AVELOCITY / BPHYS_DATA_XCONST */
        "", // BPHYS_DATA_SIZE:
 -      "", // BPHYS_DATA_TIMES:
 +      "", // BPHYS_DATA_TIMES:        
        "BoidData" // case BPHYS_DATA_BOIDS:
  };
  static void direct_link_pointcache(FileData *fd, PointCache *cache)
@@@ -3369,34 -3404,33 +3405,33 @@@ static void lib_link_particlesettings(F
                        if (part->dupliweights.first && part->dup_group) {
                                int index_ok = 0;
                                /* check for old files without indices (all indexes 0) */
-                               dw = part->dupliweights.first;
                                if (part->dupliweights.first == part->dupliweights.last) {
                                        /* special case for only one object in the group */
                                        index_ok = 1;
                                }
 -                              else {
 +                              else { 
-                                       for (; dw; dw=dw->next) {
+                                       for (dw = part->dupliweights.first; dw; dw = dw->next) {
                                                if (dw->index > 0) {
                                                        index_ok = 1;
                                                        break;
                                                }
                                        }
                                }
 -
 +                              
                                if (index_ok) {
                                        /* if we have indexes, let's use them */
-                                       dw = part->dupliweights.first;
-                                       for (; dw; dw=dw->next) {
+                                       for (dw = part->dupliweights.first; dw; dw = dw->next) {
                                                GroupObject *go = (GroupObject *)BLI_findlink(&part->dup_group->gobject, dw->index);
-                                               dw->ob = go ? go->ob : NULL;
+                                               dw->ob = go ? newlibadr(fd, part->id.lib, dw->ob) : NULL;
                                        }
                                }
                                else {
                                        /* otherwise try to get objects from own library (won't work on library linked groups) */
-                                       for (; dw; dw=dw->next)
+                                       for (dw = part->dupliweights.first; dw; dw = dw->next) {
                                                dw->ob = newlibadr(fd, part->id.lib, dw->ob);
 -                                      }
                                }
                        }
++                      }
                        else {
                                part->dupliweights.first = part->dupliweights.last = NULL;
                        }
@@@ -3611,7 -3645,7 +3646,7 @@@ static void lib_link_mtface(FileData *f
  
  static void lib_link_customdata_mtface(FileData *fd, Mesh *me, CustomData *fdata, int totface)
  {
 -      int i;
 +      int i;  
        for (i = 0; i < fdata->totlayer; i++) {
                CustomDataLayer *layer = &fdata->layers[i];
                
@@@ -3636,11 -3670,11 +3671,11 @@@ static void lib_link_customdata_mtpoly(
                                tf->tpage = newlibadr(fd, me->id.lib, tf->tpage);
                                if (tf->tpage && tf->tpage->id.us == 0) {
                                        tf->tpage->id.us = 1;
 -                              }
                        }
                }
        }
  }
 +}
  
  static void lib_link_mesh(FileData *fd, Main *main)
  {
@@@ -4060,7 -4094,7 +4095,7 @@@ static void lib_link_object(FileData *f
                                if (paf->type == EFF_PARTICLE) {
                                        paf->group = newlibadr_us(fd, ob->id.lib, paf->group);
                                }
 -                      }
 +                      }                               
                        
                        for (sens = ob->sensors.first; sens; sens = sens->next) {
                                for (a = 0; a < sens->totlinks; a++)
@@@ -4592,7 -4626,7 +4627,7 @@@ static void direct_link_object(FileDat
        direct_link_partdeflect(ob->pd);
        ob->soft= newdataadr(fd, ob->soft);
        if (ob->soft) {
 -              SoftBody *sb = ob->soft;
 +              SoftBody *sb = ob->soft;                
                
                sb->bpoint = NULL;      // init pointers so it gets rebuilt nicely
                sb->bspring = NULL;
@@@ -4739,7 -4773,6 +4774,7 @@@ static void lib_link_scene(FileData *fd
        Base *base, *next;
        Sequence *seq;
        SceneRenderLayer *srl;
 +      FreestyleLineSet *fls;
        TimeMarker *marker;
        
        for (sce = main->scene.first; sce; sce = sce->id.next) {
                                base->object = newlibadr_us(fd, sce->id.lib, base->object);
                                
                                if (base->object == NULL) {
-                                       BKE_reportf_wrap(fd->reports, RPT_WARNING, "LIB ERROR: object lost from scene: '%s'",
+                                       BKE_reportf_wrap(fd->reports, RPT_WARNING, TIP_("LIB ERROR: object lost from scene: '%s'"),
                                                         sce->id.name + 2);
                                        BLI_remlink(&sce->base, base);
                                        if (base == sce->basact) sce->basact = NULL;
                        for (srl = sce->r.layers.first; srl; srl = srl->next) {
                                srl->mat_override = newlibadr_us(fd, sce->id.lib, srl->mat_override);
                                srl->light_override = newlibadr_us(fd, sce->id.lib, srl->light_override);
 +                              for(fls=srl->freestyleConfig.linesets.first; fls; fls= fls->next) {
 +                                      fls->linestyle= newlibadr_us(fd, sce->id.lib, fls->linestyle);
 +                                      fls->group= newlibadr_us(fd, sce->id.lib, fls->group);
 +                              }
                        }
                        /*Game Settings: Dome Warp Text*/
                        sce->gm.dome.warptext = newlibadr(fd, sce->id.lib, sce->gm.dome.warptext);
@@@ -4915,7 -4944,6 +4950,7 @@@ static void direct_link_scene(FileData 
        Editing *ed;
        Sequence *seq;
        MetaStack *ms;
 +      SceneRenderLayer *srl;
        
        sce->theDag = NULL;
        sce->dagisvalid = 0;
                                        ed->seqbasep = (ListBase *)(poin+offset);
                                else
                                        ed->seqbasep = &ed->seqbase;
 -                      }
 +                      }                       
                        /* stack */
                        link_list(fd, &(ed->metastack));
                        
        }
        if (sce->r.ffcodecdata.properties) {
                sce->r.ffcodecdata.properties = newdataadr(fd, sce->r.ffcodecdata.properties);
 -              if (sce->r.ffcodecdata.properties) {
 +              if (sce->r.ffcodecdata.properties) { 
                        IDP_DirectLinkProperty(sce->r.ffcodecdata.properties, 
                                (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
                }
        link_list(fd, &(sce->markers));
        link_list(fd, &(sce->transform_spaces));
        link_list(fd, &(sce->r.layers));
 +
 +      for(srl = sce->r.layers.first; srl; srl = srl->next) {
 +              link_list(fd, &(srl->freestyleConfig.modules));
 +      }
 +      for(srl = sce->r.layers.first; srl; srl = srl->next) {
 +              link_list(fd, &(srl->freestyleConfig.linesets));
 +      }
        
        sce->nodetree = newdataadr(fd, sce->nodetree);
-       if (sce->nodetree)
+       if (sce->nodetree) {
+               direct_link_id(fd, &sce->nodetree->id);
                direct_link_nodetree(fd, sce->nodetree);
+       }
  
        direct_link_view_settings(fd, &sce->view_settings);
  }
@@@ -6008,11 -6031,11 +6045,11 @@@ static void direct_link_library(FileDat
                if (newmain->curlib) {
                        if (BLI_path_cmp(newmain->curlib->filepath, lib->filepath) == 0) {
                                BKE_reportf_wrap(fd->reports, RPT_WARNING,
-                                                "Library '%s', '%s' had multiple instances, save and reload!",
+                                                TIP_("Library '%s', '%s' had multiple instances, save and reload!"),
                                                 lib->name, lib->filepath);
                                
                                change_idid_adr(fd->mainlist, fd, lib, newmain->curlib);
- //                            change_idid_adr_fd(fd, lib, newmain->curlib);
+ /*                            change_idid_adr_fd(fd, lib, newmain->curlib); */
                                
                                BLI_remlink(&main->library, lib);
                                MEM_freeN(lib);
        BLI_strncpy(lib->filepath, lib->name, sizeof(lib->name));
        cleanup_path(fd->relabase, lib->filepath);
        
- //    printf("direct_link_library: name %s\n", lib->name);
- //    printf("direct_link_library: filename %s\n", lib->filename);
+ #if 0
+       printf("direct_link_library: name %s\n", lib->name);
+       printf("direct_link_library: filename %s\n", lib->filename);
+ #endif
        
        /* new main */
        newmain= MEM_callocN(sizeof(Main), "directlink");
@@@ -6350,177 -6375,6 +6389,177 @@@ static void lib_link_mask(FileData *fd
        }
  }
  
 +/* ************ READ LINE STYLE ***************** */
 +
 +static void lib_link_linestyle(FileData *fd, Main *main)
 +{
 +      FreestyleLineStyle *linestyle;
 +      LineStyleModifier *m;
 +
 +      linestyle = main->linestyle.first;
 +      while (linestyle) {
 +              if (linestyle->id.flag & LIB_NEED_LINK) {
 +                      linestyle->id.flag -= LIB_NEED_LINK;
 +
 +                      if (linestyle->id.properties) IDP_LibLinkProperty(linestyle->id.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
 +                      if (linestyle->adt) lib_link_animdata(fd, &linestyle->id, linestyle->adt);
 +                      for (m = linestyle->color_modifiers.first; m; m = m->next) {
 +                              switch (m->type) {
 +                              case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +                                      {
 +                                              LineStyleColorModifier_DistanceFromObject *cm = (LineStyleColorModifier_DistanceFromObject *)m;
 +                                              cm->target = newlibadr(fd, linestyle->id.lib, cm->target);
 +                                      }
 +                                      break;
 +                              }
 +                      }
 +                      for (m = linestyle->alpha_modifiers.first; m; m = m->next){
 +                              switch (m->type) {
 +                              case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +                                      {
 +                                              LineStyleAlphaModifier_DistanceFromObject *am = (LineStyleAlphaModifier_DistanceFromObject *)m;
 +                                              am->target = newlibadr(fd, linestyle->id.lib, am->target);
 +                                      }
 +                                      break;
 +                              }
 +                      }
 +                      for (m = linestyle->thickness_modifiers.first; m; m = m->next){
 +                              switch (m->type) {
 +                              case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +                                      {
 +                                              LineStyleThicknessModifier_DistanceFromObject *tm = (LineStyleThicknessModifier_DistanceFromObject *)m;
 +                                              tm->target = newlibadr(fd, linestyle->id.lib, tm->target);
 +                                      }
 +                                      break;
 +                              }
 +                      }
 +              }
 +              linestyle = linestyle->id.next;
 +      }
 +}
 +
 +static void direct_link_linestyle_color_modifier(FileData *fd, LineStyleModifier *modifier)
 +{
 +      switch (modifier->type) {
 +      case LS_MODIFIER_ALONG_STROKE:
 +              {
 +                      LineStyleColorModifier_AlongStroke *m = (LineStyleColorModifier_AlongStroke *)modifier;
 +                      m->color_ramp = newdataadr(fd, m->color_ramp);
 +              }
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +              {
 +                      LineStyleColorModifier_DistanceFromCamera *m = (LineStyleColorModifier_DistanceFromCamera *)modifier;
 +                      m->color_ramp = newdataadr(fd, m->color_ramp);
 +              }
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +              {
 +                      LineStyleColorModifier_DistanceFromObject *m = (LineStyleColorModifier_DistanceFromObject *)modifier;
 +                      m->color_ramp = newdataadr(fd, m->color_ramp);
 +              }
 +              break;
 +      case LS_MODIFIER_MATERIAL:
 +              {
 +                      LineStyleColorModifier_Material *m = (LineStyleColorModifier_Material *)modifier;
 +                      m->color_ramp = newdataadr(fd, m->color_ramp);
 +              }
 +              break;
 +      }
 +}
 +
 +static void direct_link_linestyle_alpha_modifier(FileData *fd, LineStyleModifier *modifier)
 +{
 +      switch (modifier->type) {
 +      case LS_MODIFIER_ALONG_STROKE:
 +              {
 +                      LineStyleAlphaModifier_AlongStroke *m = (LineStyleAlphaModifier_AlongStroke *)modifier;
 +                      m->curve = newdataadr(fd, m->curve);
 +                      direct_link_curvemapping(fd, m->curve);
 +              }
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +              {
 +                      LineStyleAlphaModifier_DistanceFromCamera *m = (LineStyleAlphaModifier_DistanceFromCamera *)modifier;
 +                      m->curve = newdataadr(fd, m->curve);
 +                      direct_link_curvemapping(fd, m->curve);
 +              }
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +              {
 +                      LineStyleAlphaModifier_DistanceFromObject *m = (LineStyleAlphaModifier_DistanceFromObject *)modifier;
 +                      m->curve = newdataadr(fd, m->curve);
 +                      direct_link_curvemapping(fd, m->curve);
 +              }
 +              break;
 +      case LS_MODIFIER_MATERIAL:
 +              {
 +                      LineStyleAlphaModifier_Material *m = (LineStyleAlphaModifier_Material *)modifier;
 +                      m->curve = newdataadr(fd, m->curve);
 +                      direct_link_curvemapping(fd, m->curve);
 +              }
 +              break;
 +      }
 +}
 +
 +static void direct_link_linestyle_thickness_modifier(FileData *fd, LineStyleModifier *modifier)
 +{
 +      switch (modifier->type) {
 +      case LS_MODIFIER_ALONG_STROKE:
 +              {
 +                      LineStyleThicknessModifier_AlongStroke *m = (LineStyleThicknessModifier_AlongStroke *)modifier;
 +                      m->curve = newdataadr(fd, m->curve);
 +                      direct_link_curvemapping(fd, m->curve);
 +              }
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +              {
 +                      LineStyleThicknessModifier_DistanceFromCamera *m = (LineStyleThicknessModifier_DistanceFromCamera *)modifier;
 +                      m->curve = newdataadr(fd, m->curve);
 +                      direct_link_curvemapping(fd, m->curve);
 +              }
 +              break;
 +      case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +              {
 +                      LineStyleThicknessModifier_DistanceFromObject *m = (LineStyleThicknessModifier_DistanceFromObject *)modifier;
 +                      m->curve = newdataadr(fd, m->curve);
 +                      direct_link_curvemapping(fd, m->curve);
 +              }
 +              break;
 +      case LS_MODIFIER_MATERIAL:
 +              {
 +                      LineStyleThicknessModifier_Material *m = (LineStyleThicknessModifier_Material *)modifier;
 +                      m->curve = newdataadr(fd, m->curve);
 +                      direct_link_curvemapping(fd, m->curve);
 +              }
 +              break;
 +      }
 +}
 +
 +static void direct_link_linestyle_geometry_modifier(FileData *fd, LineStyleModifier *modifier)
 +{
 +}
 +
 +static void direct_link_linestyle(FileData *fd, FreestyleLineStyle *linestyle)
 +{
 +      LineStyleModifier *modifier;
 +
 +      linestyle->adt= newdataadr(fd, linestyle->adt);
 +      direct_link_animdata(fd, linestyle->adt);
 +      link_list(fd, &linestyle->color_modifiers);
 +      for(modifier=linestyle->color_modifiers.first; modifier; modifier= modifier->next)
 +              direct_link_linestyle_color_modifier(fd, modifier);
 +      link_list(fd, &linestyle->alpha_modifiers);
 +      for(modifier=linestyle->alpha_modifiers.first; modifier; modifier= modifier->next)
 +              direct_link_linestyle_alpha_modifier(fd, modifier);
 +      link_list(fd, &linestyle->thickness_modifiers);
 +      for(modifier=linestyle->thickness_modifiers.first; modifier; modifier= modifier->next)
 +              direct_link_linestyle_thickness_modifier(fd, modifier);
 +      link_list(fd, &linestyle->geometry_modifiers);
 +      for(modifier=linestyle->geometry_modifiers.first; modifier; modifier= modifier->next)
 +              direct_link_linestyle_geometry_modifier(fd, modifier);
 +}
 +
  /* ************** GENERAL & MAIN ******************** */
  
  
@@@ -6555,7 -6409,6 +6594,7 @@@ static const char *dataname(short id_co
                case ID_PA: return "Data from PA";
                case ID_GD: return "Data from GD";
                case ID_MC: return "Data from MC";
 +              case ID_LS: return "Data from LS";
        }
        return "Data from Lib Block";
        
@@@ -6636,6 -6489,8 +6675,8 @@@ static BHead *read_libblock(FileData *f
        bhead = read_data_into_oldnewmap(fd, bhead, allocname);
        
        /* init pointers direct data */
+       direct_link_id(fd, id);
+       
        switch (GS(id->name)) {
                case ID_WM:
                        direct_link_windowmanager(fd, (wmWindowManager *)id);
                case ID_MSK:
                        direct_link_mask(fd, (Mask *)id);
                        break;
 +              case ID_LS:
 +                      direct_link_linestyle(fd, (FreestyleLineStyle *)id);
 +                      break;
        }
        
-       /*link direct data of ID properties*/
-       if (id->properties) {
-               id->properties = newdataadr(fd, id->properties);
-               if (id->properties) { /* this case means the data was written incorrectly, it should not happen */
-                       IDP_DirectLinkProperty(id->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
-               }
-       }
-       
        oldnewmap_free_unused(fd->datamap);
        oldnewmap_clear(fd->datamap);
        
@@@ -7208,6 -7052,20 +7241,20 @@@ static void do_version_ntree_dilateerod
        }
  }
  
+ static void do_version_ntree_defocus_264(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree)
+ {
+       bNode *node;
+       for (node = ntree->nodes.first; node; node = node->next) {
+               if (node->type == CMP_NODE_DEFOCUS) {
+                       NodeDefocus *data = node->storage;
+                       if (data->maxblur == 0.0f) {
+                               data->maxblur = 16.0f;
+                       }
+               }
+       }
+ }
  static void do_version_ntree_mask_264(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree)
  {
        bNode *node;
@@@ -7265,6 -7123,21 +7312,21 @@@ static void do_version_node_cleanup_dyn
        }
  }
  
+ static void do_version_node_fix_internal_links_264(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree)
+ {
+       bNode *node;
+       bNodeLink *link, *nextlink;
+       
+       for (node = ntree->nodes.first; node; node = node->next) {
+               for (link = node->internal_links.first; link; link = nextlink) {
+                       nextlink = link->next;
+                       if (!link->fromnode || !link->fromsock || !link->tonode || !link->tosock) {
+                               BLI_remlink(&node->internal_links, link);
+                       }
+               }
+       }
+ }
  static void do_versions(FileData *fd, Library *lib, Main *main)
  {
        /* WATCH IT!!!: pointers from libdata have not been converted */
                                        if ( (ob->dsize[i] == 0.0f) || /* simple case, user never touched dsize */
                                             (ob->size[i]  == 0.0f))   /* cant scale the dsize to give a non zero result, so fallback to 1.0f */
                                        {
 -                                              ob->dscale[i] = 1.0f;
 +                                              ob->dscale[i]= 1.0f;
                                        }
                                        else {
 -                                              ob->dscale[i] = (ob->size[i] + ob->dsize[i]) / ob->size[i];
 +                                              ob->dscale[i]= (ob->size[i] + ob->dsize[i]) / ob->size[i];
                                        }
                                }
                        }
                                        prop = BKE_bproperty_object_get(ob, "Text");
                                        if (prop) {
                                                BKE_reportf_wrap(fd->reports, RPT_WARNING,
-                                                                "Game property name conflict in object '%s':\ntext objects reserve the "
-                                                                "['Text'] game property to change their content through logic bricks",
+                                                                TIP_("Game property name conflict in object '%s':\ntext objects reserve the "
+                                                                     "['Text'] game property to change their content through logic bricks"),
                                                                 ob->id.name + 2);
                                        }
                                }
        if (main->versionfile < 263 || (main->versionfile == 263 && main->subversionfile < 10)) {
                {
                        Scene *scene;
+                       bNodeTreeType *ntreetype;
                        // composite redesign
                        for (scene=main->scene.first; scene; scene=scene->id.next) {
                                if (scene->nodetree) {
                                        }
                                }
                        }
+                       ntreetype = ntreeGetType(NTREE_COMPOSIT);
+       
+                       if (ntreetype && ntreetype->foreach_nodetree)
+                               ntreetype->foreach_nodetree(main, NULL, do_version_ntree_defocus_264);
+                       
                }
  
                {
                        do_version_node_cleanup_dynamic_sockets_264(NULL, NULL, ntree);
        }
  
+       if (main->versionfile < 264 || (main->versionfile == 264 && main->subversionfile < 5)) {
+               /* set a unwrapping margin and ABF by default */
+               Scene *scene;
+               for (scene=main->scene.first; scene; scene=scene->id.next) {
+                       if (scene->toolsettings->uvcalc_margin == 0.0f) {
+                               scene->toolsettings->uvcalc_margin = 0.001f;
+                               scene->toolsettings->unwrapper = 0;
+                       }
+               }
+       }
+       if (main->versionfile < 264 || (main->versionfile == 264 && main->subversionfile < 6)) {
+               /* Fix for bug #32982, internal_links list could get corrupted from r51630 onward.
+                * Simply remove bad internal_links lists to avoid NULL pointers.
+                */
+               bNodeTreeType *ntreetype;
+               bNodeTree *ntree;
+               
+               ntreetype = ntreeGetType(NTREE_COMPOSIT);
+               if (ntreetype && ntreetype->foreach_nodetree)
+                       ntreetype->foreach_nodetree(main, NULL, do_version_node_fix_internal_links_264);
+               ntreetype = ntreeGetType(NTREE_SHADER);
+               if (ntreetype && ntreetype->foreach_nodetree)
+                       ntreetype->foreach_nodetree(main, NULL, do_version_node_fix_internal_links_264);
+               ntreetype = ntreeGetType(NTREE_TEXTURE);
+               if (ntreetype && ntreetype->foreach_nodetree)
+                       ntreetype->foreach_nodetree(main, NULL, do_version_node_fix_internal_links_264);
+               
+               for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next)
+                       do_version_node_fix_internal_links_264(NULL, NULL, ntree);
+               
+       }
 +      /* default values in Freestyle settings */
 +      {
 +              Scene *sce;
 +              SceneRenderLayer *srl;
 +              FreestyleLineStyle *linestyle;
 +
 +              for(sce = main->scene.first; sce; sce = sce->id.next) {
 +                      if (sce->r.line_thickness_mode == 0) {
 +                              sce->r.line_thickness_mode= R_LINE_THICKNESS_ABSOLUTE;
 +                              sce->r.unit_line_thickness= 1.f;
 +                      }
 +                      for(srl= sce->r.layers.first; srl; srl= srl->next) {
 +                              if (srl->freestyleConfig.mode == 0)
 +                                      srl->freestyleConfig.mode= FREESTYLE_CONTROL_EDITOR_MODE;
 +                              if (srl->freestyleConfig.raycasting_algorithm == FREESTYLE_ALGO_CULLED_ADAPTIVE_CUMULATIVE ||
 +                                      srl->freestyleConfig.raycasting_algorithm == FREESTYLE_ALGO_CULLED_ADAPTIVE_TRADITIONAL) {
 +                                      srl->freestyleConfig.raycasting_algorithm= 0; /* deprecated */
 +                                      srl->freestyleConfig.flags |= FREESTYLE_CULLING;
 +                              }
 +                      }
 +              }
 +              for(linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
 +                      if (linestyle->thickness_position == 0) {
 +                              linestyle->thickness_position= LS_THICKNESS_CENTER;
 +                              linestyle->thickness_ratio= 0.5f;
 +                      }
 +                      if (linestyle->chaining == 0)
 +                              linestyle->chaining= LS_CHAINING_PLAIN;
 +                      if (linestyle->rounds == 0)
 +                              linestyle->rounds= 3;
 +              }
 +      }
 +
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
        /* WATCH IT 2!: Userdef struct init has to be in editors/interface/resources.c! */
  
@@@ -8413,7 -8293,6 +8515,7 @@@ static void lib_link_all(FileData *fd, 
        lib_link_particlesettings(fd, main);
        lib_link_movieclip(fd, main);
        lib_link_mask(fd, main);
 +      lib_link_linestyle(fd, main);
  
        lib_link_mesh(fd, main);                /* as last: tpage images with users at zero */
        
@@@ -9024,7 -8903,7 +9126,7 @@@ static void expand_curve(FileData *fd, 
        }
        
        expand_doit(fd, mainvar, cu->vfont);
 -      expand_doit(fd, mainvar, cu->vfontb);
 +      expand_doit(fd, mainvar, cu->vfontb);   
        expand_doit(fd, mainvar, cu->vfonti);
        expand_doit(fd, mainvar, cu->vfontbi);
        expand_doit(fd, mainvar, cu->key);
@@@ -9328,7 -9207,6 +9430,7 @@@ static void expand_scene(FileData *fd, 
  {
        Base *base;
        SceneRenderLayer *srl;
 +      FreestyleLineSet *lineset;
        
        for (base = sce->base.first; base; base = base->next) {
                expand_doit(fd, mainvar, base->object);
        for (srl = sce->r.layers.first; srl; srl = srl->next) {
                expand_doit(fd, mainvar, srl->mat_override);
                expand_doit(fd, mainvar, srl->light_override);
 +
 +              for (lineset = srl->freestyleConfig.linesets.first; lineset; lineset = lineset->next) {
 +                      if (lineset->group)
 +                              expand_doit(fd, mainvar, lineset->group);
 +                      expand_doit(fd, mainvar, lineset->linestyle);
 +              }
        }
        
        if (sce->r.dometext)
@@@ -9448,26 -9320,6 +9550,26 @@@ static void expand_mask(FileData *fd, M
        }
  }
  
 +static void expand_linestyle(FileData *fd, Main *mainvar, FreestyleLineStyle *linestyle)
 +{
 +      LineStyleModifier *m;
 +
 +      if (linestyle->adt)
 +              expand_animdata(fd, mainvar, linestyle->adt);
 +      for (m = linestyle->color_modifiers.first; m; m = m->next) {
 +              if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT)
 +                      expand_doit(fd, mainvar, ((LineStyleColorModifier_DistanceFromObject *)m)->target);
 +      }
 +      for (m = linestyle->alpha_modifiers.first; m; m = m->next){
 +              if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT)
 +                      expand_doit(fd, mainvar, ((LineStyleAlphaModifier_DistanceFromObject *)m)->target);
 +      }
 +      for (m = linestyle->thickness_modifiers.first; m; m = m->next){
 +              if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT)
 +                      expand_doit(fd, mainvar, ((LineStyleThicknessModifier_DistanceFromObject *)m)->target);
 +      }
 +}
 +
  static void expand_main(FileData *fd, Main *mainvar)
  {
        ListBase *lbarray[MAX_LIBARRAY];
                                        case ID_MSK:
                                                expand_mask(fd, mainvar, (Mask *)id);
                                                break;
 +                                      case ID_LS:
 +                                              expand_linestyle(fd, mainvar, (FreestyleLineStyle *)id);
 +                                              break;
                                        }
                                        
                                        do_it = TRUE;
@@@ -9876,7 -9725,7 +9978,7 @@@ static void library_append_end(const bC
        if ((*fd)->flags & FD_FLAGS_SWITCH_ENDIAN) {
                blo_freefiledata(*fd);
                *fd = NULL;
 -      }
 +      }       
  }
  
  void BLO_library_append_end(const bContext *C, struct Main *mainl, BlendHandle** bh, int idcode, short flag)
@@@ -9931,8 -9780,7 +10033,7 @@@ static void read_libraries(FileData *ba
                                
                                if (fd == NULL) {
                                        /* printf and reports for now... its important users know this */
-                                       BKE_reportf_wrap(basefd->reports, RPT_INFO,
-                                                        "Read library:  '%s', '%s'",
+                                       BKE_reportf_wrap(basefd->reports, RPT_INFO, TIP_("Read library:  '%s', '%s'"),
                                                         mainptr->curlib->filepath, mainptr->curlib->name);
                                        
                                        fd = blo_openblenderfile(mainptr->curlib->filepath, basefd->reports);
                                        else mainptr->curlib->filedata = NULL;
                                        
                                        if (fd == NULL) {
-                                               BKE_reportf_wrap(basefd->reports, RPT_WARNING,
-                                                                "Cannot find lib '%s'",
+                                               BKE_reportf_wrap(basefd->reports, RPT_WARNING, TIP_("Cannot find lib '%s'"),
                                                                 mainptr->curlib->filepath);
                                        }
                                }
                                                                append_id_part(fd, mainptr, id, &realid);
                                                                if (!realid) {
                                                                        BKE_reportf_wrap(fd->reports, RPT_WARNING,
-                                                                                        "LIB ERROR: %s:'%s' missing from '%s'",
+                                                                                        TIP_("LIB ERROR: %s: '%s' missing from '%s'"),
                                                                                         BKE_idcode_to_name(GS(id->name)),
                                                                                         id->name+2, mainptr->curlib->filepath);
                                                                }
                                if (id->flag & LIB_READ) {
                                        BLI_remlink(lbarray[a], id);
                                        BKE_reportf_wrap(basefd->reports, RPT_WARNING,
-                                                        "LIB ERROR: %s:'%s' unread libblock missing from '%s'",
+                                                        TIP_("LIB ERROR: %s: '%s' unread lib block missing from '%s'"),
                                                         BKE_idcode_to_name(GS(id->name)), id->name + 2, mainptr->curlib->filepath);
                                        change_idid_adr(mainlist, basefd, id, NULL);
                                        
index 99283cf9473425457e467ad121cdbadc79af9a5f,9588636789731e8b6eccdb87aa15b003209d691e..ea8b566340d01a7255838342ee46eb2e2ecde0d6
  #include "DNA_key_types.h"
  #include "DNA_lattice_types.h"
  #include "DNA_lamp_types.h"
 +#include "DNA_linestyle_types.h"
  #include "DNA_meta_types.h"
  #include "DNA_mesh_types.h"
  #include "DNA_meshdata_types.h"
@@@ -198,7 -197,7 +198,7 @@@ static WriteData *writedata_new(int fil
  
        if (wd == NULL) return NULL;
  
-       wd->sdna= DNA_sdna_from_data(DNAstr, DNAlen, 0);
+       wd->sdna = DNA_sdna_from_data(DNAstr, DNAlen, 0);
  
        wd->file= file;
  
@@@ -512,7 -511,7 +512,7 @@@ static void write_fcurves(WriteData *wd
                writestruct(wd, DATA, "FCurve", 1, fcu);
                
                /* curve data */
-               if (fcu->bezt)          
+               if (fcu->bezt)
                        writestruct(wd, DATA, "BezTriple", fcu->totvert, fcu->bezt);
                if (fcu->fpt)
                        writestruct(wd, DATA, "FPoint", fcu->totvert, fcu->fpt);
@@@ -721,7 -720,9 +721,9 @@@ static void write_nodetree(WriteData *w
                        write_node_socket(wd, sock);
                for (sock= node->outputs.first; sock; sock= sock->next)
                        write_node_socket(wd, sock);
+               
+               for (link = node->internal_links.first; link; link = link->next)
+                       writestruct(wd, DATA, "bNodeLink", 1, link);
                
                if (node->storage) {
                        /* could be handlerized at some point, now only 1 exception still */
@@@ -889,7 -890,7 +891,7 @@@ static const char *ptcache_data_struct[
        "", // BPHYS_DATA_ROTATION
        "", // BPHYS_DATA_AVELOCITY / BPHYS_DATA_XCONST */
        "", // BPHYS_DATA_SIZE:
-       "", // BPHYS_DATA_TIMES:        
+       "", // BPHYS_DATA_TIMES:
        "BoidData" // case BPHYS_DATA_BOIDS:
  };
  static const char *ptcache_extra_struct[] = {
@@@ -1242,7 -1243,7 +1244,7 @@@ static void write_constraints(WriteDat
                                        break;
                                case CONSTRAINT_TYPE_SPLINEIK: 
                                {
-                                       bSplineIKConstraint *data= (bSplineIKConstraint*)con->data;
+                                       bSplineIKConstraint *data = (bSplineIKConstraint *)con->data;
                                        
                                        /* write points array */
                                        writedata(wd, DATA, sizeof(float)*(data->numpoints), data->points);
@@@ -1330,7 -1331,7 +1332,7 @@@ static void write_modifiers(WriteData *
                        writestruct(wd, DATA, "ClothCollSettings", 1, clmd->coll_parms);
                        writestruct(wd, DATA, "EffectorWeights", 1, clmd->sim_parms->effector_weights);
                        write_pointcaches(wd, &clmd->ptcaches);
-               } 
+               }
                else if (md->type==eModifierType_Smoke) {
                        SmokeModifierData *smd = (SmokeModifierData*) md;
                        
                                writestruct(wd, DATA, "SmokeFlowSettings", 1, smd->flow);
                        else if (smd->type & MOD_SMOKE_TYPE_COLL)
                                writestruct(wd, DATA, "SmokeCollSettings", 1, smd->coll);
-               } 
+               }
                else if (md->type==eModifierType_Fluidsim) {
                        FluidsimModifierData *fluidmd = (FluidsimModifierData*) md;
                        
                                writestruct(wd, DATA, "ColorBand", 1, pmd->brush->paint_ramp);
                                writestruct(wd, DATA, "ColorBand", 1, pmd->brush->vel_ramp);
                        }
-               } 
+               }
                else if (md->type==eModifierType_Collision) {
                        
  #if 0
@@@ -1608,7 -1609,7 +1610,7 @@@ static void write_curves(WriteData *wd
                        if (cu->vfont) {
                                writedata(wd, DATA, amount_of_chars(cu->str)+1, cu->str);
                                writestruct(wd, DATA, "CharInfo", cu->len+1, cu->strinfo);
-                               writestruct(wd, DATA, "TextBox", cu->totbox, cu->tb);                           
+                               writestruct(wd, DATA, "TextBox", cu->totbox, cu->tb);
                        }
                        else {
                                /* is also the order of reading */
@@@ -2026,7 -2027,7 +2028,7 @@@ static void write_materials(WriteData *
                                write_nodetree(wd, ma->nodetree);
                        }
  
-                       write_previews(wd, ma->preview);                        
+                       write_previews(wd, ma->preview);
                }
                ma= ma->id.next;
        }
@@@ -2082,7 -2083,7 +2084,7 @@@ static void write_lamps(WriteData *wd, 
                        }
                        
                        if (la->curfalloff)
-                               write_curvemapping(wd, la->curfalloff); 
+                               write_curvemapping(wd, la->curfalloff);
                        
                        /* nodetree is integral part of lamps, no libdata */
                        if (la->nodetree) {
@@@ -2142,8 -2143,6 +2144,8 @@@ static void write_scenes(WriteData *wd
        TimeMarker *marker;
        TransformOrientation *ts;
        SceneRenderLayer *srl;
 +      FreestyleModuleConfig *fmc;
 +      FreestyleLineSet *fls;
        ToolSettings *tos;
        
        sce= scebase->first;
                for (ts = sce->transform_spaces.first; ts; ts = ts->next)
                        writestruct(wd, DATA, "TransformOrientation", 1, ts);
                
 -              for (srl= sce->r.layers.first; srl; srl= srl->next)
 +              for (srl= sce->r.layers.first; srl; srl= srl->next) {
                        writestruct(wd, DATA, "SceneRenderLayer", 1, srl);
 +                      
 +                      for(fmc= srl->freestyleConfig.modules.first; fmc; fmc = fmc->next) {
 +                              writestruct(wd, DATA, "FreestyleModuleConfig", 1, fmc);
 +                      }
 +                      
 +                      for(fls= srl->freestyleConfig.linesets.first; fls; fls = fls->next) {
 +                              writestruct(wd, DATA, "FreestyleLineSet", 1, fls);
 +                      }
 +
 +              }
                
                if (sce->nodetree) {
                        writestruct(wd, DATA, "bNodeTree", 1, sce->nodetree);
@@@ -2317,7 -2306,7 +2319,7 @@@ static void write_gpencils(WriteData *w
                                        /* write strokes */
                                        for (gps= gpf->strokes.first; gps; gps= gps->next) {
                                                writestruct(wd, DATA, "bGPDstroke", 1, gps);
-                                               writestruct(wd, DATA, "bGPDspoint", gps->totpoints, gps->points);                               
+                                               writestruct(wd, DATA, "bGPDspoint", gps->totpoints, gps->points);
                                        }
                                }
                        }
@@@ -2553,7 -2542,7 +2555,7 @@@ static void write_bone(WriteData *wd, B
        Bone*   cbone;
  
        // PATCH for upward compatibility after 2.37+ armature recode
-       bone->size[0]= bone->size[1]= bone->size[2]= 1.0f;
+       bone->size[0] = bone->size[1] = bone->size[2] = 1.0f;
                
        // Write this bone
        writestruct(wd, DATA, "Bone", 1, bone);
@@@ -2863,205 -2852,6 +2865,205 @@@ static void write_masks(WriteData *wd, 
        mywrite(wd, MYWRITE_FLUSH, 0);
  }
  
 +static void write_linestyle_color_modifiers(WriteData *wd, ListBase *modifiers)
 +{
 +      LineStyleModifier *m;
 +      char *struct_name;
 +
 +      for (m = modifiers->first; m; m = m->next) {
 +              switch (m->type) {
 +              case LS_MODIFIER_ALONG_STROKE:
 +                      struct_name = "LineStyleColorModifier_AlongStroke";
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +                      struct_name = "LineStyleColorModifier_DistanceFromCamera";
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +                      struct_name = "LineStyleColorModifier_DistanceFromObject";
 +                      break;
 +              case LS_MODIFIER_MATERIAL:
 +                      struct_name = "LineStyleColorModifier_Material";
 +                      break;
 +              default:
 +                      struct_name = "LineStyleColorModifier"; // this should not happen
 +              }
 +              writestruct(wd, DATA, struct_name, 1, m);
 +      }
 +      for (m = modifiers->first; m; m = m->next) {
 +              switch (m->type) {
 +              case LS_MODIFIER_ALONG_STROKE:
 +                      writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_AlongStroke *)m)->color_ramp);
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +                      writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp);
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +                      writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp);
 +                      break;
 +              case LS_MODIFIER_MATERIAL:
 +                      writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_Material *)m)->color_ramp);
 +                      break;
 +              }
 +      }
 +}
 +
 +static void write_linestyle_alpha_modifiers(WriteData *wd, ListBase *modifiers)
 +{
 +      LineStyleModifier *m;
 +      char *struct_name;
 +
 +      for (m = modifiers->first; m; m = m->next) {
 +              switch (m->type) {
 +              case LS_MODIFIER_ALONG_STROKE:
 +                      struct_name = "LineStyleAlphaModifier_AlongStroke";
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +                      struct_name = "LineStyleAlphaModifier_DistanceFromCamera";
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +                      struct_name = "LineStyleAlphaModifier_DistanceFromObject";
 +                      break;
 +              case LS_MODIFIER_MATERIAL:
 +                      struct_name = "LineStyleAlphaModifier_Material";
 +                      break;
 +              default:
 +                      struct_name = "LineStyleAlphaModifier"; // this should not happen
 +              }
 +              writestruct(wd, DATA, struct_name, 1, m);
 +      }
 +      for (m = modifiers->first; m; m = m->next) {
 +              switch (m->type) {
 +              case LS_MODIFIER_ALONG_STROKE:
 +                      write_curvemapping(wd, ((LineStyleAlphaModifier_AlongStroke *)m)->curve);
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +                      write_curvemapping(wd, ((LineStyleAlphaModifier_DistanceFromCamera *)m)->curve);
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +                      write_curvemapping(wd, ((LineStyleAlphaModifier_DistanceFromObject *)m)->curve);
 +                      break;
 +              case LS_MODIFIER_MATERIAL:
 +                      write_curvemapping(wd, ((LineStyleAlphaModifier_Material *)m)->curve);
 +                      break;
 +              }
 +      }
 +}
 +
 +static void write_linestyle_thickness_modifiers(WriteData *wd, ListBase *modifiers)
 +{
 +      LineStyleModifier *m;
 +      char *struct_name;
 +
 +      for (m = modifiers->first; m; m = m->next) {
 +              switch (m->type) {
 +              case LS_MODIFIER_ALONG_STROKE:
 +                      struct_name = "LineStyleThicknessModifier_AlongStroke";
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +                      struct_name = "LineStyleThicknessModifier_DistanceFromCamera";
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +                      struct_name = "LineStyleThicknessModifier_DistanceFromObject";
 +                      break;
 +              case LS_MODIFIER_MATERIAL:
 +                      struct_name = "LineStyleThicknessModifier_Material";
 +                      break;
 +              case LS_MODIFIER_CALLIGRAPHY:
 +                      struct_name = "LineStyleThicknessModifier_Calligraphy";
 +                      break;
 +              default:
 +                      struct_name = "LineStyleThicknessModifier"; // this should not happen
 +              }
 +              writestruct(wd, DATA, struct_name, 1, m);
 +      }
 +      for (m = modifiers->first; m; m = m->next) {
 +              switch (m->type) {
 +              case LS_MODIFIER_ALONG_STROKE:
 +                      write_curvemapping(wd, ((LineStyleThicknessModifier_AlongStroke *)m)->curve);
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_CAMERA:
 +                      write_curvemapping(wd, ((LineStyleThicknessModifier_DistanceFromCamera *)m)->curve);
 +                      break;
 +              case LS_MODIFIER_DISTANCE_FROM_OBJECT:
 +                      write_curvemapping(wd, ((LineStyleThicknessModifier_DistanceFromObject *)m)->curve);
 +                      break;
 +              case LS_MODIFIER_MATERIAL:
 +                      write_curvemapping(wd, ((LineStyleThicknessModifier_Material *)m)->curve);
 +                      break;
 +              }
 +      }
 +}
 +
 +static void write_linestyle_geometry_modifiers(WriteData *wd, ListBase *modifiers)
 +{
 +      LineStyleModifier *m;
 +      char *struct_name;
 +
 +      for (m = modifiers->first; m; m = m->next) {
 +              switch (m->type) {
 +              case LS_MODIFIER_SAMPLING:
 +                      struct_name = "LineStyleGeometryModifier_Sampling";
 +                      break;
 +              case LS_MODIFIER_BEZIER_CURVE:
 +                      struct_name = "LineStyleGeometryModifier_BezierCurve";
 +                      break;
 +              case LS_MODIFIER_SINUS_DISPLACEMENT:
 +                      struct_name = "LineStyleGeometryModifier_SinusDisplacement";
 +                      break;
 +              case LS_MODIFIER_SPATIAL_NOISE:
 +                      struct_name = "LineStyleGeometryModifier_SpatialNoise";
 +                      break;
 +              case LS_MODIFIER_PERLIN_NOISE_1D:
 +                      struct_name = "LineStyleGeometryModifier_PerlinNoise1D";
 +                      break;
 +              case LS_MODIFIER_PERLIN_NOISE_2D:
 +                      struct_name = "LineStyleGeometryModifier_PerlinNoise2D";
 +                      break;
 +              case LS_MODIFIER_BACKBONE_STRETCHER:
 +                      struct_name = "LineStyleGeometryModifier_BackboneStretcher";
 +                      break;
 +              case LS_MODIFIER_TIP_REMOVER:
 +                      struct_name = "LineStyleGeometryModifier_TipRemover";
 +                      break;
 +              case LS_MODIFIER_POLYGONIZATION:
 +                      struct_name = "LineStyleGeometryModifier_Polygonalization";
 +                      break;
 +              case LS_MODIFIER_GUIDING_LINES:
 +                      struct_name = "LineStyleGeometryModifier_GuidingLines";
 +                      break;
 +              case LS_MODIFIER_BLUEPRINT:
 +                      struct_name = "LineStyleGeometryModifier_Blueprint";
 +                      break;
 +              case LS_MODIFIER_2D_OFFSET:
 +                      struct_name = "LineStyleGeometryModifier_2DOffset";
 +                      break;
 +              case LS_MODIFIER_2D_TRANSFORM:
 +                      struct_name = "LineStyleGeometryModifier_2DTransform";
 +                      break;
 +              default:
 +                      struct_name = "LineStyleGeometryModifier"; // this should not happen
 +              }
 +              writestruct(wd, DATA, struct_name, 1, m);
 +      }
 +}
 +
 +static void write_linestyles(WriteData *wd, ListBase *idbase)
 +{
 +      FreestyleLineStyle *linestyle;
 +
 +      for(linestyle=idbase->first; linestyle; linestyle= linestyle->id.next) {
 +              if(linestyle->id.us>0 || wd->current) {
 +                      writestruct(wd, ID_LS, "FreestyleLineStyle", 1, linestyle);
 +                      if (linestyle->id.properties) IDP_WriteProperty(linestyle->id.properties, wd);
 +                      if (linestyle->adt) write_animdata(wd, linestyle->adt);
 +                      write_linestyle_color_modifiers(wd, &linestyle->color_modifiers);
 +                      write_linestyle_alpha_modifiers(wd, &linestyle->alpha_modifiers);
 +                      write_linestyle_thickness_modifiers(wd, &linestyle->thickness_modifiers);
 +                      write_linestyle_geometry_modifiers(wd, &linestyle->geometry_modifiers);
 +              }
 +      }
 +}
 +
  /* context is usually defined by WM, two cases where no WM is available:
   * - for forward compatibility, curscreen has to be saved
   * - for undofile, curscene needs to be saved */
@@@ -3172,7 -2962,6 +3174,7 @@@ static int write_file_handle(Main *main
        write_brushes  (wd, &mainvar->brush);
        write_scripts  (wd, &mainvar->script);
        write_gpencils (wd, &mainvar->gpencil);
 +      write_linestyles(wd, &mainvar->linestyle);
        write_libraries(wd,  mainvar->next);
  
        if (write_user_block) {
@@@ -3212,7 -3001,7 +3214,7 @@@ static int do_history(const char *name
                if (BLI_rename(tempname1, tempname2)) {
                        BKE_report(reports, RPT_ERROR, "Unable to make version backup");
                        return 1;
-               }       
+               }
                hisnr--;
        }
  
@@@ -3287,7 -3076,7 +3289,7 @@@ int BLO_write_file(Main *mainvar, cons
  
        /* file save to temporary file was successful */
        /* now do reverse file history (move .blend1 -> .blend2, .blend -> .blend1) */
-       if (write_flags & G_FILE_HISTORY) { 
+       if (write_flags & G_FILE_HISTORY) {
                int err_hist = do_history(filepath, reports);
                if (err_hist) {
                        BKE_report(reports, RPT_ERROR, "Version backup failed (file saved with @)");
index 998407c82baa361d2d619fc85c6a9afc82885878,cff7da78ef27efd477ab9c6bc17b6db2c664f624..bdca301171497d6f75aa2c7c9d99c39feafeac9a
@@@ -225,10 -225,8 +225,9 @@@ enum 
  
        BM_ELEM_DRAW    = (1 << 5), /* edge display */
  
-       /* we have 1 spare flag which is awesome but since we're limited to 8
-        * only add new flags with care! - campbell */
-       /* BM_ELEM_SPARE  = (1 << 6), */
+       /* spare tag, assumed dirty, use define in each function to name based on use */
+       // _BM_ELEM_TAG_ALT = (1 << 6),  // UNUSED
 +      BM_ELEM_FREESTYLE = (1 << 6), /* used for Freestyle faces and edges */
  
        BM_ELEM_INTERNAL_TAG = (1 << 7) /* for low level internal API tagging,
                                       * since tools may want to tag verts and
index 6ccd0cbc491bfdd95e9667640017fc67a2ef1e81,d86a26e19ac7ef2c241a62d5647fe570f0d8d891..645e4e348e83c7fe6c50908bd641c28bec892919
@@@ -725,6 -725,7 +725,7 @@@ static void bm_vert_attrs_copy(BMesh *s
                                 const BMVert *source_vertex, BMVert *target_vertex)
  {
        if ((source_mesh == target_mesh) && (source_vertex == target_vertex)) {
+               BLI_assert(!"BMVert: source and targer match");
                return;
        }
        copy_v3_v3(target_vertex->no, source_vertex->no);
@@@ -737,6 -738,7 +738,7 @@@ static void bm_edge_attrs_copy(BMesh *s
                                 const BMEdge *source_edge, BMEdge *target_edge)
  {
        if ((source_mesh == target_mesh) && (source_edge == target_edge)) {
+               BLI_assert(!"BMEdge: source and targer match");
                return;
        }
        CustomData_bmesh_free_block(&target_mesh->edata, &target_edge->head.data);
@@@ -748,6 -750,7 +750,7 @@@ static void bm_loop_attrs_copy(BMesh *s
                                 const BMLoop *source_loop, BMLoop *target_loop)
  {
        if ((source_mesh == target_mesh) && (source_loop == target_loop)) {
+               BLI_assert(!"BMLoop: source and targer match");
                return;
        }
        CustomData_bmesh_free_block(&target_mesh->ldata, &target_loop->head.data);
@@@ -759,6 -762,7 +762,7 @@@ static void bm_face_attrs_copy(BMesh *s
                                 const BMFace *source_face, BMFace *target_face)
  {
        if ((source_mesh == target_mesh) && (source_face == target_face)) {
+               BLI_assert(!"BMFace: source and targer match");
                return;
        }
        copy_v3_v3(target_face->no, source_face->no);
@@@ -781,8 -785,10 +785,10 @@@ void BM_elem_attrs_copy(BMesh *source_m
  
        BLI_assert(sheader->htype == theader->htype);
  
-       if (sheader->htype != theader->htype)
+       if (sheader->htype != theader->htype) {
+               BLI_assert(!"type mismatch");
                return;
+       }
  
        /* First we copy select */
        if (BM_elem_flag_test((BMElem *)sheader, BM_ELEM_SELECT)) {
@@@ -976,16 -982,14 +982,16 @@@ char BM_edge_flag_from_mflag(const shor
                 ((meflag & ME_SEAM)       ? BM_ELEM_SEAM   : 0) |
                 ((meflag & ME_EDGEDRAW)   ? BM_ELEM_DRAW   : 0) |
                 ((meflag & ME_SHARP) == 0 ? BM_ELEM_SMOOTH : 0) | /* invert */
 -               ((meflag & ME_HIDE)       ? BM_ELEM_HIDDEN : 0)
 +               ((meflag & ME_HIDE)       ? BM_ELEM_HIDDEN : 0) |
 +               ((meflag & ME_FREESTYLE_EDGE) ? BM_ELEM_FREESTYLE : 0)
                 );
  }
  char BM_face_flag_from_mflag(const char  meflag)
  {
        return ( ((meflag & ME_FACE_SEL)  ? BM_ELEM_SELECT : 0) |
                 ((meflag & ME_SMOOTH)    ? BM_ELEM_SMOOTH : 0) |
 -               ((meflag & ME_HIDE)      ? BM_ELEM_HIDDEN : 0)
 +               ((meflag & ME_HIDE)      ? BM_ELEM_HIDDEN : 0) |
 +               ((meflag & ME_FREESTYLE_FACE) ? BM_ELEM_FREESTYLE : 0)
                 );
  }
  
@@@ -1008,7 -1012,6 +1014,7 @@@ short BM_edge_flag_to_mflag(BMEdge *eed
                 ((hflag & BM_ELEM_DRAW)         ? ME_EDGEDRAW  : 0) |
                 ((hflag & BM_ELEM_SMOOTH) == 0  ? ME_SHARP     : 0) |
                 ((hflag & BM_ELEM_HIDDEN)       ? ME_HIDE      : 0) |
 +               ((hflag & BM_ELEM_FREESTYLE)    ? ME_FREESTYLE_EDGE : 0) |
                 ((BM_edge_is_wire(eed))         ? ME_LOOSEEDGE : 0) | /* not typical */
                 ME_EDGERENDER
                 );
@@@ -1019,7 -1022,6 +1025,7 @@@ char  BM_face_flag_to_mflag(BMFace *efa
  
        return ( ((hflag & BM_ELEM_SELECT) ? ME_FACE_SEL : 0) |
                 ((hflag & BM_ELEM_SMOOTH) ? ME_SMOOTH   : 0) |
 -               ((hflag & BM_ELEM_HIDDEN) ? ME_HIDE     : 0)
 +               ((hflag & BM_ELEM_HIDDEN) ? ME_HIDE     : 0) |
 +               ((hflag & BM_ELEM_FREESTYLE) ? ME_FREESTYLE_FACE : 0)
                 );
  }
index 3d792205d08148295b4e1aa85bfc67004bb1d0e8,42c5557327b5e3c22c525fca4f9fdf9ab9e93c3a..b396da3b8d1281bb2b5cc27f3fabd01ce96e8772
@@@ -668,13 -668,6 +668,13 @@@ void bmo_similar_faces_exec(BMesh *bm, 
                                                        cont = FALSE;
                                                }
                                                break;
 +
 +                                      case SIMFACE_FREESTYLE:
 +                                              if (BM_elem_flag_test(fm, BM_ELEM_FREESTYLE) == BM_elem_flag_test(fs, BM_ELEM_FREESTYLE)) {
 +                                                      BMO_elem_flag_enable(bm, fm, FACE_MARK);
 +                                                      cont = 0;
 +                                              }
 +                                              break;
                                }
                        }
                }
@@@ -880,13 -873,6 +880,13 @@@ void bmo_similar_edges_exec(BMesh *bm, 
                                                        cont = FALSE;
                                                }
                                                break;
 +
 +                                      case SIMEDGE_FREESTYLE:
 +                                              if (BM_elem_flag_test(e, BM_ELEM_FREESTYLE) == BM_elem_flag_test(es, BM_ELEM_FREESTYLE)) {
 +                                                      BMO_elem_flag_enable(bm, e, EDGE_MARK);
 +                                                      cont = 0;
 +                                              }
 +                                              break;
                                }
                        }
                }
@@@ -1295,7 -1281,7 +1295,7 @@@ void bmo_shortest_path_exec(BMesh *bm, 
                vert_list[i].hn = BLI_heap_insert(h, vert_list[i].weight, vert_list[i].v);
        }
  
-       while (!BLI_heap_empty(h)) {
+       while (!BLI_heap_is_empty(h)) {
                BMEdge *e;
                BMIter e_i;
                float v_weight;
index 12c0e851f8894c8ee542ed4d8da6e006548b8ff2,573ebe156c575726a5f4662badb8da349d43bcc8..81ebca7b2fbaea13fc59d78e18223d2229f90d88
@@@ -47,7 -47,6 +47,7 @@@
  #include "DNA_key_types.h"
  #include "DNA_lamp_types.h"
  #include "DNA_lattice_types.h"
 +#include "DNA_linestyle_types.h"
  #include "DNA_mesh_types.h"
  #include "DNA_material_types.h"
  #include "DNA_meta_types.h"
@@@ -1187,7 -1186,7 +1187,7 @@@ static void *acf_dsmat_setting_ptr(bAni
                        if (ma->adt)
                                return GET_ACF_FLAG_PTR(ma->adt->flag, type);
                        else
-                               return NULL;    
+                               return NULL;
                
                default: /* unsupported */
                        return NULL;
@@@ -1264,7 -1263,7 +1264,7 @@@ static void *acf_dslam_setting_ptr(bAni
                        if (la->adt)
                                return GET_ACF_FLAG_PTR(la->adt->flag, type);
                        else
-                               return NULL;    
+                               return NULL;
                
                default: /* unsupported */
                        return NULL;
@@@ -1348,7 -1347,7 +1348,7 @@@ static void *acf_dstex_setting_ptr(bAni
                        if (tex->adt)
                                return GET_ACF_FLAG_PTR(tex->adt->flag, type);
                        else
-                               return NULL;    
+                               return NULL;
                
                default: /* unsupported */
                        return NULL;
@@@ -2011,83 -2010,6 +2011,83 @@@ static bAnimChannelType ACF_DSNTREE 
        acf_dsntree_setting_ptr                 /* pointer for setting */
  };
  
 +/* LineStyle Expander  ------------------------------------------- */
 +
 +// TODO: just get this from RNA?
 +static int acf_dslinestyle_icon(bAnimListElem *ale)
 +{
 +      return ICON_BRUSH_DATA; /* FIXME */
 +}
 +
 +/* get the appropriate flag(s) for the setting when it is valid  */
 +static int acf_dslinestyle_setting_flag(bAnimContext *ac, int setting, short *neg)
 +{
 +      /* clear extra return data first */
 +      *neg= 0;
 +      
 +      switch (setting) {
 +              case ACHANNEL_SETTING_EXPAND: /* expanded */
 +                      return LS_DS_EXPAND;
 +                      
 +              case ACHANNEL_SETTING_MUTE: /* mute (only in NLA) */
 +                      return ADT_NLA_EVAL_OFF;
 +                      
 +              case ACHANNEL_SETTING_VISIBLE: /* visible (only in Graph Editor) */
 +                      *neg= 1;
 +                      return ADT_CURVES_NOT_VISIBLE;
 +                      
 +              case ACHANNEL_SETTING_SELECT: /* selected */
 +                      return ADT_UI_SELECTED;
 +                      
 +              default: /* unsupported */
 +                      return 0;
 +      }
 +}
 +
 +/* get pointer to the setting */
 +static void *acf_dslinestyle_setting_ptr(bAnimListElem *ale, int setting, short *type)
 +{
 +      FreestyleLineStyle *linestyle= (FreestyleLineStyle *)ale->data;
 +      
 +      /* clear extra return data first */
 +      *type= 0;
 +      
 +      switch (setting) {
 +              case ACHANNEL_SETTING_EXPAND: /* expanded */
 +                      return GET_ACF_FLAG_PTR(linestyle->flag, type);
 +                      
 +              case ACHANNEL_SETTING_SELECT: /* selected */
 +              case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */
 +              case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */
 +                      if (linestyle->adt)
 +                              return GET_ACF_FLAG_PTR(linestyle->adt->flag, type);
 +                      else
 +                              return NULL;
 +                      
 +              default: /* unsupported */
 +                      return NULL;
 +      }
 +}
 +
 +/* node tree expander type define */
 +static bAnimChannelType ACF_DSLINESTYLE= 
 +{
 +      "Line Style Expander",                  /* type name */
 +      
 +      acf_generic_dataexpand_color,   /* backdrop color */
 +      acf_generic_dataexpand_backdrop,/* backdrop */
 +      acf_generic_indention_1,                /* indent level */
 +      acf_generic_basic_offset,               /* offset */
 +      
 +      acf_generic_idblock_name,               /* name */
 +      acf_generic_idblock_nameprop,   /* name prop */
 +      acf_dslinestyle_icon,                   /* icon */
 +      
 +      acf_generic_dataexpand_setting_valid,   /* has setting */
 +      acf_dslinestyle_setting_flag,                   /* flag for setting */
 +      acf_dslinestyle_setting_ptr                             /* pointer for setting */
 +};
 +
  /* Mesh Expander  ------------------------------------------- */
  
  // TODO: just get this from RNA?
@@@ -2800,7 -2722,6 +2800,7 @@@ static void ANIM_init_channel_typeinfo_
                animchannelTypeInfo[type++] = &ACF_DSTEX;        /* Texture Channel */
                animchannelTypeInfo[type++] = &ACF_DSLAT;        /* Lattice Channel */
                animchannelTypeInfo[type++] = &ACF_DSSPK;        /* Speaker Channel */
 +              animchannelTypeInfo[type++] = &ACF_DSLINESTYLE;  /* LineStyle Channel */
                
                animchannelTypeInfo[type++] = &ACF_SHAPEKEY;     /* ShapeKey */
                
@@@ -3330,7 -3251,7 +3330,7 @@@ static void draw_setting_widget(bAnimCo
        /* get the flag and the pointer to that flag */
        flag = acf->setting_flag(ac, setting, &negflag);
        ptr = acf->setting_ptr(ale, setting, &ptrsize);
-       /* enabled= ANIM_channel_setting_get(ac, ale, setting); */ /* UNUSED */
+       /* enabled = ANIM_channel_setting_get(ac, ale, setting); */ /* UNUSED */
        
        /* get the base icon for the setting */
        switch (setting) {
                        break;
                        
                case ACHANNEL_SETTING_EXPAND: /* expanded triangle */
-                       //icon= ((enabled)? ICON_TRIA_DOWN : ICON_TRIA_RIGHT);
+                       //icon = ((enabled)? ICON_TRIA_DOWN : ICON_TRIA_RIGHT);
                        icon = ICON_TRIA_RIGHT;
                        tooltip = "Make channels grouped under this channel visible";
                        break;
                        
                case ACHANNEL_SETTING_SOLO: /* NLA Tracks only */
-                       //icon= ((enabled)? ICON_LAYER_ACTIVE : ICON_LAYER_USED);
+                       //icon = ((enabled)? ICON_LAYER_ACTIVE : ICON_LAYER_USED);
                        icon = ICON_LAYER_USED;
                        tooltip = "NLA Track is the only one evaluated for the AnimData block it belongs to";
                        break;
                
                case ACHANNEL_SETTING_PROTECT: /* protected lock */
                        // TODO: what about when there's no protect needed?
-                       //icon= ((enabled)? ICON_LOCKED : ICON_UNLOCKED);
+                       //icon = ((enabled)? ICON_LOCKED : ICON_UNLOCKED);
                        icon = ICON_UNLOCKED;
                        tooltip = "Editability of keyframes for this channel";
                        break;
                        
                case ACHANNEL_SETTING_MUTE: /* muted speaker */
-                       //icon= ((enabled)? ICON_MUTE_IPO_ON : ICON_MUTE_IPO_OFF);
+                       //icon = ((enabled)? ICON_MUTE_IPO_ON : ICON_MUTE_IPO_OFF);
                        icon = ICON_MUTE_IPO_OFF;
                        
                        if (ale->type == ALE_FCURVE) 
@@@ -3449,7 -3370,7 +3449,7 @@@ void ANIM_channel_draw_widgets(bContex
        y = (ymaxc - yminc) / 2 + yminc;
        ymid = y - 7;
        /* y-coordinates for text is only 4 down from middle */
-       /* ytext= y - 4; */
+       /* ytext = y - 4; */
        
        /* no button backdrop behind icons */
        uiBlockSetEmboss(block, UI_EMBOSSN);
index ee31276a8c4e533f74b4dd2b84aa31dadcf8cd5a,f19dbe740bcd1e9fc6f5a5f4211c4640be819f67..f6459bfc54268555785959374e3fa61efa803559
@@@ -124,7 -124,6 +124,7 @@@ void ANIM_set_active_channel(bAnimConte
                        case ANIMTYPE_DSMESH:
                        case ANIMTYPE_DSTEX:
                        case ANIMTYPE_DSLAT:
 +                      case ANIMTYPE_DSLINESTYLE:
                        case ANIMTYPE_DSSPK:
                        {
                                /* need to verify that this data is valid for now */
                        case ANIMTYPE_DSARM:
                        case ANIMTYPE_DSMESH:
                        case ANIMTYPE_DSLAT:
 +                      case ANIMTYPE_DSLINESTYLE:
                        case ANIMTYPE_DSSPK:
                        {
                                /* need to verify that this data is valid for now */
@@@ -251,7 -249,6 +251,7 @@@ void ANIM_deselect_anim_channels(bAnimC
                                case ANIMTYPE_DSNTREE:
                                case ANIMTYPE_DSTEX:
                                case ANIMTYPE_DSLAT:
 +                              case ANIMTYPE_DSLINESTYLE:
                                case ANIMTYPE_DSSPK:
                                {
                                        if ((ale->adt) && (ale->adt->flag & ADT_UI_SELECTED))
                        case ANIMTYPE_DSNTREE:
                        case ANIMTYPE_DSTEX:
                        case ANIMTYPE_DSLAT:
 +                      case ANIMTYPE_DSLINESTYLE:
                        case ANIMTYPE_DSSPK:
                        {
                                /* need to verify that this data is valid for now */
@@@ -468,7 -464,7 +468,7 @@@ void ANIM_flush_setting_anim_channels(b
                                
                                /* store this level as the 'old' level now */
                                prevLevel = level;
-                       }       
+                       }
                        /* if the level is 'greater than' (i.e. less important) than the previous level... */
                        else if (level > prevLevel) {
                                /* if previous level was a base-level (i.e. 0 offset / root of one hierarchy),
@@@ -604,7 -600,7 +604,7 @@@ static int animedit_poll_channels_nla_t
        if (ELEM3(sa->spacetype, SPACE_ACTION, SPACE_IPO, SPACE_NLA) == 0)
                return 0;
        
-       /* NLA TweakMode test */        
+       /* NLA TweakMode test */
        if (sa->spacetype == SPACE_NLA) {
                if ((scene == NULL) || (scene->flag & SCE_NLA_EDIT_ON))
                        return 0;
@@@ -798,7 -794,7 +798,7 @@@ static void rearrange_animchannel_add_t
                        FCurve *fcu = (FCurve *)channel;
                        
                        is_sel = SEL_FCU(fcu);
-               }       
+               }
                break;
                case ANIMTYPE_NLATRACK:
                {
@@@ -914,7 -910,7 +914,7 @@@ static void rearrange_nla_channels(bAni
        if (rearrange_func == NULL)
                return;
        
-       /* only consider NLA data if it's accessible */ 
+       /* only consider NLA data if it's accessible */
        //if (EXPANDED_DRVD(adt) == 0)
        //      return;
        
@@@ -935,7 -931,7 +935,7 @@@ static void rearrange_driver_channels(b
        if (rearrange_func == NULL)
                return;
        
-       /* only consider drivers if they're accessible */       
+       /* only consider drivers if they're accessible */
        if (EXPANDED_DRVD(adt) == 0)
                return;
        
@@@ -2189,7 -2185,6 +2189,7 @@@ static int mouse_anim_channels(bAnimCon
                case ANIMTYPE_DSNTREE:
                case ANIMTYPE_DSTEX:
                case ANIMTYPE_DSLAT:
 +              case ANIMTYPE_DSLINESTYLE:
                case ANIMTYPE_DSSPK:
                {
                        /* sanity checking... */
                        }
                        
                        notifierFlags |= (ND_ANIMCHAN | NA_SELECTED);
-               }       
+       }
                break;
                
                case ANIMTYPE_GROUP: 
                                agrp->flag ^= AGRP_SELECTED;
                        }
                        else if (selectmode == -1) {
-                               /* select all in group (and deselect everthing else) */ 
+                               /* select all in group (and deselect everthing else) */
                                FCurve *fcu;
                                
                                /* deselect all other channels */
                                /* only select channels in group and group itself */
                                for (fcu = agrp->channels.first; fcu && fcu->grp == agrp; fcu = fcu->next)
                                        fcu->flag |= FCURVE_SELECTED;
-                               agrp->flag |= AGRP_SELECTED;                                    
+                               agrp->flag |= AGRP_SELECTED;
                        }
                        else {
                                /* select group by itself */
                                /* invert selection status of this layer only */
                                gpl->flag ^= GP_LAYER_SELECT;
                        }
-                       else {  
+                       else {
                                /* select layer by itself */
                                ANIM_deselect_anim_channels(ac, ac->data, ac->datatype, 0, ACHANNEL_SETFLAG_CLEAR);
                                gpl->flag |= GP_LAYER_SELECT;
index 9b88c307cb63023db806d587ee08f6ae3c44bab7,721b347379208f9031582fd169e4983d2b3fee7f..f1fc93db60ef97f1bac8e749365e6d17265d2959
@@@ -55,7 -55,6 +55,7 @@@
  #include "DNA_camera_types.h"
  #include "DNA_lamp_types.h"
  #include "DNA_lattice_types.h"
 +#include "DNA_linestyle_types.h"
  #include "DNA_key_types.h"
  #include "DNA_mask_types.h"
  #include "DNA_material_types.h"
@@@ -683,7 -682,7 +683,7 @@@ static bAnimListElem *make_new_animlist
                                ale->datatype = ALE_ACT;
                                
                                ale->adt = BKE_animdata_from_id(data);
-                       }       
+                       }
                        break;
                        case ANIMTYPE_DSSPK:
                        {
                                ale->adt = BKE_animdata_from_id(data);
                        }
                        break;
 +                      case ANIMTYPE_DSLINESTYLE:
 +                      {
 +                              FreestyleLineStyle *linestyle= (FreestyleLineStyle *)data;
 +                              AnimData *adt= linestyle->adt;
 +                              
 +                              ale->flag= FILTER_LS_SCED(linestyle); 
 +                              
 +                              ale->key_data= (adt) ? adt->action : NULL;
 +                              ale->datatype= ALE_ACT;
 +                              
 +                              ale->adt= BKE_animdata_from_id(data);
 +                      }
 +                              break;
                        case ANIMTYPE_DSPART:
                        {
                                ParticleSettings *part = (ParticleSettings *)ale->data;
                                        }
                                        ale->datatype = (ale->key_data) ? ALE_FCURVE : ALE_NONE;
                                }
-                       }       
+                       }
                        break;
                        
                        case ANIMTYPE_GPLAYER:
@@@ -1037,7 -1023,7 +1037,7 @@@ static FCurve *animfilter_fcurve_next(b
                                if (skip_fcurve_selected_data(ads, fcu, owner_id, filter_mode))
                                        continue;
                        }
-               }       
+               }
                
                /* only include if visible (Graph Editor check, not channels check) */
                if (!(filter_mode & ANIMFILTER_CURVE_VISIBLE) || (fcu->flag & FCURVE_VISIBLE)) {
@@@ -1225,7 -1211,7 +1225,7 @@@ static size_t animfilter_nla(bAnimConte
                 */
                if (!(ads->filterflag & ADS_FILTER_NLA_NOACT) || (adt->action)) {
                        /* there isn't really anything editable here, so skip if need editable */
-                       if ((filter_mode & ANIMFILTER_FOREDIT) == 0) { 
+                       if ((filter_mode & ANIMFILTER_FOREDIT) == 0) {
                                /* just add the action track now (this MUST appear for drawing)
                                 *      - as AnimData may not have an action, we pass a dummy pointer just to get the list elem created, then
                                 *        overwrite this with the real value - REVIEW THIS...
@@@ -1525,54 -1511,6 +1525,54 @@@ static size_t animdata_filter_ds_nodetr
        return items;
  }
  
 +static size_t animdata_filter_ds_linestyle (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode)
 +{
 +      SceneRenderLayer *srl;
 +      size_t items = 0;
 +
 +      for (srl= sce->r.layers.first; srl; srl= srl->next) {
 +              FreestyleLineSet *lineset;
 +
 +              /* skip render layers without Freestyle enabled */
 +              if (!(srl->layflag & SCE_LAY_FRS))
 +                      continue;
 +
 +              /* loop over linesets defined in the render layer */
 +              for (lineset= srl->freestyleConfig.linesets.first; lineset; lineset= lineset->next) {
 +                      FreestyleLineStyle *linestyle = lineset->linestyle;
 +                      ListBase tmp_data = {NULL, NULL};
 +                      size_t tmp_items = 0;
 +
 +                      /* add scene-level animation channels */
 +                      BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_LS_SCED(linestyle))
 +                      {
 +                              /* animation data filtering */
 +                              tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)linestyle, filter_mode);
 +                      }
 +                      END_ANIMFILTER_SUBCHANNELS;
 +
 +                      /* did we find anything? */
 +                      if (tmp_items) {
 +                              /* include anim-expand widget first */
 +                              if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
 +                                      /* check if filtering by active status */
 +                                      if ANIMCHANNEL_ACTIVEOK(linestyle) {
 +                                              ANIMCHANNEL_NEW_CHANNEL(linestyle, ANIMTYPE_DSLINESTYLE, sce);
 +                                      }
 +                              }
 +                              
 +                              /* now add the list of collected channels */
 +                              BLI_movelisttolist(anim_data, &tmp_data);
 +                              BLI_assert((tmp_data.first == tmp_data.last) && (tmp_data.first == NULL));
 +                              items += tmp_items;
 +                      }
 +              }
 +      }
 +      
 +      /* return the number of items added to the list */
 +      return items;
 +}
 +
  /* NOTE: owner_id is either material, lamp, or world block, which is the direct owner of the texture stack in question */
  static size_t animdata_filter_ds_textures(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, ID *owner_id, int filter_mode)
  {
@@@ -2207,11 -2145,6 +2207,11 @@@ static size_t animdata_filter_dopesheet
                        tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, (ID *)sce, ntree, filter_mode);
                }
  
 +              /* line styles */
 +              if ((ads->filterflag & ADS_FILTER_NOLINESTYLE) == 0) {
 +                      tmp_items += animdata_filter_ds_linestyle(ac, &tmp_data, ads, sce, filter_mode);
 +              }
 +              
                /* TODO: one day, when sequencer becomes its own datatype, perhaps it should be included here */
        }
        END_ANIMFILTER_SUBCHANNELS;
index 974d492a364bbfd5c250c8f080ffb5f694456066,24aca0c037da01901d52e0419c238fe11dfaa148..c7e6a5f2882ad1dc128d192368cafe748e14691d
@@@ -175,7 -175,7 +175,7 @@@ static uiBlock *id_search_menu(bContex
        idptr = RNA_property_pointer_get(&template.ptr, template.prop);
  
        block = uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
-       uiBlockSetFlag(block, UI_BLOCK_LOOP | UI_BLOCK_REDRAW | UI_BLOCK_RET_1);
+       uiBlockSetFlag(block, UI_BLOCK_LOOP | UI_BLOCK_REDRAW | UI_BLOCK_SEARCH_MENU);
        
        /* preview thumbnails */
        if (template.prv_rows > 0 && template.prv_cols > 0) {
                
        
        uiBoundsBlock(block, 6);
-       uiBlockSetDirection(block, UI_DOWN);    
+       uiBlockSetDirection(block, UI_DOWN);
        uiEndBlock(C, block);
        
        /* give search-field focus */
@@@ -336,7 -336,6 +336,7 @@@ static const char *template_id_browse_t
                        case ID_BR: return N_("Browse Brush to be linked");
                        case ID_PA: return N_("Browse Particle System to be linked");
                        case ID_GD: return N_("Browse Grease Pencil Data to be linked");
 +                      case ID_LS: return N_("Browse Line Style Data to be linked");
                }
        }
        return N_("Browse ID data to be linked");
@@@ -401,7 -400,7 +401,7 @@@ static void template_ID(bContext *C, ui
  
                //text_idbutton(id, name);
                name[0] = '\0';
-               but = uiDefButR(block, TEX, 0, name, 0, 0, UI_UNIT_X * 6, UI_UNIT_Y, &idptr, "name", -1, 0, 0, -1, -1, NULL);
+               but = uiDefButR(block, TEX, 0, name, 0, 0, UI_UNIT_X * 6, UI_UNIT_Y, &idptr, "name", -1, 0, 0, -1, -1, RNA_struct_ui_description(type));
                uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_RENAME));
                if (user_alert) uiButSetFlag(but, UI_BUT_REDALERT);
  
@@@ -581,7 -580,7 +581,7 @@@ void uiTemplateAnyID(uiLayout *layout, 
                RNA_warning("pointer property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
                return;
        }
-       if (!propType || RNA_property_type(propType) != PROP_ENUM) { 
+       if (!propType || RNA_property_type(propType) != PROP_ENUM) {
                RNA_warning("pointer-type property not found: %s.%s", RNA_struct_identifier(ptr->type), proptypename);
                return;
        }
@@@ -1222,7 -1221,7 +1222,7 @@@ void uiTemplatePreview(uiLayout *layout
                        else ma = (Material *)pparent;
                        
                        /* Create RNA Pointer */
-                       RNA_pointer_create(id, &RNA_Material, ma, &material_ptr);
+                       RNA_pointer_create(&ma->id, &RNA_Material, ma, &material_ptr);
  
                        col = uiLayoutColumn(row, TRUE);
                        uiLayoutSetScaleX(col, 1.5);
@@@ -1282,7 -1281,7 +1282,7 @@@ static void colorband_add_cb(bContext *
  
        if (colorband_element_add(coba, pos)) {
                rna_update_cb(C, cb_v, NULL);
-               ED_undo_push(C, "Add colorband");       
+               ED_undo_push(C, "Add colorband");
        }
  }
  
@@@ -1406,7 -1405,7 +1406,7 @@@ static void colorband_buttons_small(uiL
                uiItemR(layout, &ptr, "color", 0, "", ICON_NONE);
        }
  
-       bt = uiDefButS(block, MENU, 0, TIP_("Interpolation %t|Ease %x1|Cardinal %x3|Linear %x0|B-Spline %x2|Constant %x4"),
+       bt = uiDefButS(block, MENU, 0, IFACE_("Interpolation %t|Ease %x1|Cardinal %x3|Linear %x0|B-Spline %x2|Constant %x4"),
                       xs + 10.0f * unit, butr->ymin + UI_UNIT_Y, unit * 4, UI_UNIT_Y,     &coba->ipotype, 0.0, 0.0, 0, 0,
                       TIP_("Set interpolation between color stops"));
        uiButSetNFunc(bt, rna_update_cb, MEM_dupallocN(cb), NULL);
@@@ -2238,7 -2237,7 +2238,7 @@@ static void list_item_row(bContext *C, 
                uiBlockSetEmboss(block, UI_EMBOSS);
                uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, ptr, "use_textures", i, 0, 0, 0, 0,  NULL);
        }
 -      else if (RNA_struct_is_a(itemptr->type, &RNA_SceneRenderLayer)) {
 +      else if (RNA_struct_is_a(itemptr->type, &RNA_SceneRenderLayer) || RNA_struct_is_a(itemptr->type, &RNA_FreestyleLineSet)) {
                uiItemL(sub, name, icon);
                uiBlockSetEmboss(block, UI_EMBOSS);
                uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "use", 0, 0, 0, 0, 0,  NULL);
@@@ -2745,7 -2744,7 +2745,7 @@@ void uiTemplateRunningJobs(uiLayout *la
                uiDefIconTextBut(block, BUT, B_STOPCAST, ICON_CANCEL, IFACE_("Capture"), 0, 0, 85, UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0,
                                 TIP_("Stop screencast"));
        if (screen->animtimer)
-               uiDefIconTextBut(block, BUT, B_STOPANIM, ICON_CANCEL, TIP_("Anim Player"), 0, 0, 100, UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0,
+               uiDefIconTextBut(block, BUT, B_STOPANIM, ICON_CANCEL, IFACE_("Anim Player"), 0, 0, 100, UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0,
                                 TIP_("Stop animation playback"));
  }
  
@@@ -2775,8 -2774,8 +2775,8 @@@ void uiTemplateReportsBanner(uiLayout *
        block = uiLayoutGetBlock(ui_abs);
        
        width = BLF_width(style->widget.uifont_id, report->message);
-       width = MIN2(rti->widthfac * width, width);
-       width = MAX2(width, 10);
+       width = min_ii((int)(rti->widthfac * width), width);
+       width = max_ii(width, 10);
        
        /* make a box around the report to make it stand out */
        uiBlockBeginAlign(block);
index a964052cc23b9629d5c7a65b1d5b20d0621e9869,e03a288786653b3cf4d51f1dc888b23be9d7b7e9..de79a290cb3e3bd35c80a5043f7ea2c6779095d3
@@@ -343,10 -343,6 +343,10 @@@ const unsigned char *UI_ThemeGetColorPt
                                        cp = ts->handle_sel_vect; break;
                                case TH_HANDLE_SEL_ALIGN:
                                        cp = ts->handle_sel_align; break;
 +                              case TH_FREESTYLE_EDGE_MARK:
 +                                      cp = ts->freestyle_edge_mark; break;
 +                              case TH_FREESTYLE_FACE_MARK:
 +                                      cp = ts->freestyle_face_mark; break;
  
                                case TH_SYNTAX_B:
                                        cp = ts->syntaxb; break;
@@@ -655,7 -651,7 +655,7 @@@ void ui_theme_init_default(void
                strcpy(btheme->name, "Default");
        }
        
-       UI_SetTheme(0, 0);  // make sure the global used in this file is set
+       UI_SetTheme(0, 0);  /* make sure the global used in this file is set */
  
        /* UI buttons */
        ui_widget_color_init(&btheme->tui);
        rgba_char_args_set(btheme->tv3d.button_text_hi, 255, 255, 255, 255);
        rgba_char_args_set(btheme->tv3d.button_title, 0, 0, 0, 255);
        rgba_char_args_set(btheme->tv3d.title, 0, 0, 0, 255);
 +      rgba_char_args_set(btheme->tv3d.freestyle_edge_mark, 0x7f, 0xff, 0x7f, 255);
 +      rgba_char_args_set(btheme->tv3d.freestyle_face_mark, 0x7f, 0xff, 0x7f, 51);
  
        btheme->tv3d.facedot_size = 4;
  
        rgba_char_args_set_fl(btheme->tfile.list, 0.4, 0.4, 0.4, 1);
        rgba_char_args_set(btheme->tfile.text,  250, 250, 250, 255);
        rgba_char_args_set(btheme->tfile.text_hi, 15, 15, 15, 255);
-       rgba_char_args_set(btheme->tfile.panel, 145, 145, 145, 255);    // bookmark/ui regions
-       rgba_char_args_set(btheme->tfile.active, 130, 130, 130, 255); // selected files
-       rgba_char_args_set(btheme->tfile.hilite, 255, 140, 25, 255); // selected files
+       rgba_char_args_set(btheme->tfile.panel, 145, 145, 145, 255);  /* bookmark/ui regions */
+       rgba_char_args_set(btheme->tfile.active, 130, 130, 130, 255); /* selected files */
+       rgba_char_args_set(btheme->tfile.hilite, 255, 140, 25, 255);  /* selected files */
        
        rgba_char_args_set(btheme->tfile.grid,  250, 250, 250, 255);
        rgba_char_args_set(btheme->tfile.image, 250, 250, 250, 255);
        btheme->ttime = btheme->tv3d;
        rgba_char_args_set_fl(btheme->ttime.back,   0.45, 0.45, 0.45, 1.0);
        rgba_char_args_set_fl(btheme->ttime.grid,   0.36, 0.36, 0.36, 1.0);
-       rgba_char_args_set(btheme->ttime.shade1,  173, 173, 173, 255);      // sliders
+       rgba_char_args_set(btheme->ttime.shade1,  173, 173, 173, 255);      /* sliders */
        
        /* space node, re-uses syntax color storage */
        btheme->tnode = btheme->tv3d;
  
  void UI_SetTheme(int spacetype, int regionid)
  {
-       if (spacetype == 0) { // called for safety, when delete themes
+       if (spacetype == 0) {  /* called for safety, when delete themes */
                theme_active = U.themes.first;
                theme_spacetype = SPACE_VIEW3D;
                theme_regionid = RGN_TYPE_WINDOW;
@@@ -956,7 -950,7 +956,7 @@@ bTheme *UI_GetTheme(void
        return U.themes.first;
  }
  
- // for space windows only
+ /* for space windows only */
  void UI_ThemeColor(int colorid)
  {
        const unsigned char *cp;
  
  }
  
- // plus alpha
+ /* plus alpha */
  void UI_ThemeColor4(int colorid)
  {
        const unsigned char *cp;
  
  }
  
- // set the color with offset for shades
+ /* set the color with offset for shades */
  void UI_ThemeColorShade(int colorid, int offset)
  {
        int r, g, b;
@@@ -1009,7 -1003,7 +1009,7 @@@ void UI_ThemeColorShadeAlpha(int colori
        glColor4ub(r, g, b, a);
  }
  
- // blend between to theme colors, and set it
+ /* blend between to theme colors, and set it */
  void UI_ThemeColorBlend(int colorid1, int colorid2, float fac)
  {
        int r, g, b;
        glColor3ub(r, g, b);
  }
  
- // blend between to theme colors, shade it, and set it
+ /* blend between to theme colors, shade it, and set it */
  void UI_ThemeColorBlendShade(int colorid1, int colorid2, float fac, int offset)
  {
        int r, g, b;
        glColor3ub(r, g, b);
  }
  
- // blend between to theme colors, shade it, and set it
+ /* blend between to theme colors, shade it, and set it */
  void UI_ThemeColorBlendShadeAlpha(int colorid1, int colorid2, float fac, int offset, int alphaoffset)
  {
        int r, g, b, a;
  }
  
  
- // get individual values, not scaled
+ /* get individual values, not scaled */
  float UI_GetThemeValuef(int colorid)
  {
        const unsigned char *cp;
  
  }
  
- // get individual values, not scaled
+ /* get individual values, not scaled */
  int UI_GetThemeValue(int colorid)
  {
        const unsigned char *cp;
  }
  
  
- // get the color, range 0.0-1.0
+ /* get the color, range 0.0-1.0 */
  void UI_GetThemeColor3fv(int colorid, float col[3])
  {
        const unsigned char *cp;
@@@ -1114,7 -1108,7 +1114,7 @@@ void UI_GetThemeColor4fv(int colorid, f
        col[3] = ((float)cp[3]) / 255.0f;
  }
  
- // get the color, range 0.0-1.0, complete with shading offset
+ /* get the color, range 0.0-1.0, complete with shading offset */
  void UI_GetThemeColorShade3fv(int colorid, int offset, float col[3])
  {
        int r, g, b;
@@@ -1153,7 -1147,7 +1153,7 @@@ void UI_GetThemeColorShade3ubv(int colo
        col[2] = b;
  }
  
- // get the color, in char pointer
+ /* get the color, in char pointer */
  void UI_GetThemeColor3ubv(int colorid, unsigned char col[3])
  {
        const unsigned char *cp;
        col[2] = cp[2];
  }
  
- // get the color, in char pointer
+ /* get the color, in char pointer */
  void UI_GetThemeColor4ubv(int colorid, unsigned char col[4])
  {
        const unsigned char *cp;
@@@ -1187,7 -1181,7 +1187,7 @@@ void UI_GetThemeColorType4ubv(int color
        col[3] = cp[3];
  }
  
- // blends and shades between two char color pointers
+ /* blends and shades between two char color pointers */
  void UI_ColorPtrBlendShade3ubv(const unsigned char cp1[3], const unsigned char cp2[3], float fac, int offset)
  {
        int r, g, b;
@@@ -1220,7 -1214,7 +1220,7 @@@ void UI_GetColorPtrShade3ubv(const unsi
        col[2] = b;
  }
  
- // get a 3 byte color, blended and shaded between two other char color pointers
+ /* get a 3 byte color, blended and shaded between two other char color pointers */
  void UI_GetColorPtrBlendShade3ubv(const unsigned char cp1[3], const unsigned char cp2[3], unsigned char col[3],
                                    float fac, int offset)
  {
@@@ -1366,7 -1360,7 +1366,7 @@@ void init_userdef_do_versions(void
                                btheme->ttime = btheme->tv3d;
                                rgba_char_args_set_fl(btheme->ttime.back,   0.45, 0.45, 0.45, 1.0);
                                rgba_char_args_set_fl(btheme->ttime.grid,   0.36, 0.36, 0.36, 1.0);
-                               rgba_char_args_set(btheme->ttime.shade1,  173, 173, 173, 255);      // sliders
+                               rgba_char_args_set(btheme->ttime.shade1,  173, 173, 173, 255);  /* sliders */
                        }
                        if (btheme->text.syntaxn[3] == 0) {
                                rgba_char_args_set(btheme->text.syntaxn,    0, 0, 200, 255);    /* Numbers  Blue*/
                }
        }
  
 +      /* Freestyle color settings */
 +      {
 +              bTheme *btheme;
 +
 +              for(btheme= U.themes.first; btheme; btheme= btheme->next) {
 +                      /* check for alpha==0 is safe, then color was never set */
 +                      if(btheme->tv3d.freestyle_edge_mark[3]==0) {
 +                              rgba_char_args_set(btheme->tv3d.freestyle_edge_mark, 0x7f, 0xff, 0x7f, 255);
 +                              rgba_char_args_set(btheme->tv3d.freestyle_face_mark, 0x7f, 0xff, 0x7f, 51);
 +                      }
 +              }
 +      }
 +
        /* GL Texture Garbage Collection (variable abused above!) */
        if (U.textimeout == 0) {
                U.texcollectrate = 60;
index bc792037443fb0690a3df31489adf038a111ce97,03c88c4a9da0543d1a646cef7bd0db11de1f7d48..99eee19f66d431d700b4c1e5253f3069b4d61d3e
@@@ -686,7 -686,6 +686,7 @@@ static EnumPropertyItem prop_similar_ty
        {SIMEDGE_BEVEL, "BEVEL", 0, "Bevel", ""},
        {SIMEDGE_SEAM, "SEAM", 0, "Seam", ""},
        {SIMEDGE_SHARP, "SHARP", 0, "Sharpness", ""},
 +      {SIMEDGE_FREESTYLE, "FREESTYLE_EDGE", 0, "Freestyle Edge Marks", ""},
  
        {SIMFACE_MATERIAL, "MATERIAL", 0, "Material", ""},
        {SIMFACE_IMAGE, "IMAGE", 0, "Image", ""},
        {SIMFACE_PERIMETER, "PERIMETER", 0, "Perimeter", ""},
        {SIMFACE_NORMAL, "NORMAL", 0, "Normal", ""},
        {SIMFACE_COPLANAR, "COPLANAR", 0, "Co-planar", ""},
 +      {SIMFACE_FREESTYLE, "FREESTYLE_FACE", 0, "Freestyle Face Marks", ""},
  
        {0, NULL, 0, NULL, NULL}
  };
@@@ -860,7 -858,7 +860,7 @@@ static EnumPropertyItem *select_similar
                        }
                }
                else if (em->selectmode & SCE_SELECT_FACE) {
 -                      for (a = SIMFACE_MATERIAL; a <= SIMFACE_COPLANAR; a++) {
 +                      for (a = SIMFACE_MATERIAL; a <= SIMFACE_FREESTYLE; a++) {
                                RNA_enum_items_add_value(&item, &totitem, prop_similar_types, a);
                        }
                }
@@@ -1220,9 -1218,6 +1220,9 @@@ static void edgetag_context_set(BMEditM
                case EDGE_MODE_TAG_SHARP:
                        BM_elem_flag_set(e, BM_ELEM_SMOOTH, !val);
                        break;
 +              case EDGE_MODE_TAG_FREESTYLE:
 +                      BM_elem_flag_set(e, BM_ELEM_FREESTYLE, val);
 +                      break;
                case EDGE_MODE_TAG_CREASE:
                {
                        float *crease = CustomData_bmesh_get(&em->bm->edata, e->head.data, CD_CREASE);
@@@ -1247,8 -1242,6 +1247,8 @@@ static int edgetag_context_check(Scene 
                        return BM_elem_flag_test(e, BM_ELEM_SEAM);
                case EDGE_MODE_TAG_SHARP:
                        return !BM_elem_flag_test(e, BM_ELEM_SMOOTH);
 +              case EDGE_MODE_TAG_FREESTYLE:
 +                      return !BM_elem_flag_test(e, BM_ELEM_FREESTYLE);
                case EDGE_MODE_TAG_CREASE:
                        return BM_elem_float_data_get(&em->bm->edata, e, CD_CREASE) ? 1 : 0;
                case EDGE_MODE_TAG_BEVEL:
@@@ -1333,7 -1326,7 +1333,7 @@@ static int edgetag_shortest_path(Scene 
        EDBM_index_arrays_init(em, 1, 1, 0);
        targetnum = BM_elem_index_get(target);
  
-       while (!BLI_heap_empty(heap)) {
+       while (!BLI_heap_is_empty(heap)) {
                mednum = GET_INT_FROM_POINTER(BLI_heap_popmin(heap));
                e = EDBM_edge_at_index(em, mednum);
  
@@@ -1444,15 -1437,12 +1444,15 @@@ static int mouse_mesh_shortest_path(bCo
                        case EDGE_MODE_TAG_SHARP:
                                me->drawflag |= ME_DRAWSHARP;
                                break;
-                       case EDGE_MODE_TAG_CREASE:      
+                       case EDGE_MODE_TAG_CREASE:
                                me->drawflag |= ME_DRAWCREASES;
                                break;
                        case EDGE_MODE_TAG_BEVEL:
                                me->drawflag |= ME_DRAWBWEIGHTS;
                                break;
 +                      case EDGE_MODE_TAG_FREESTYLE:
 +                              me->drawflag |= ME_DRAW_FREESTYLE_EDGE;
 +                              break;
                }
                
                EDBM_update_generic(C, em, FALSE);
@@@ -1717,7 -1707,7 +1717,7 @@@ void EDBM_selectmode_convert(BMEditMes
                                        BM_edge_select_set(em->bm, eed, TRUE);
                                }
                        }
-               }               
+               }
                else if (selectmode_new == SCE_SELECT_FACE) {
                        BMIter liter;
                        BMLoop *l;
@@@ -2482,7 -2472,7 +2482,7 @@@ static int edbm_select_non_manifold_exe
         */
        
        if (em->selectmode == SCE_SELECT_FACE) {
-               BKE_report(op->reports, RPT_ERROR, "Doesn't work in face selection mode");
+               BKE_report(op->reports, RPT_ERROR, "Does not work in face selection mode");
                return OPERATOR_CANCELLED;
        }
        
index ee615093c86925f09367dd90fc37f860e15fa430,fd3eabdaec37b35e11e2834c136c1a82f4524306..9d3cc7b7c76974f802bb90a5e62f180c0762121f
@@@ -255,7 -255,7 +255,7 @@@ static short edbm_extrude_discrete_face
                return 0;
        }
  
-       return 's'; // s is shrink/fatten
+       return 's';  /* s is shrink/fatten */
  }
  
  /* extrudes individual edges */
@@@ -275,7 -275,7 +275,7 @@@ static short edbm_extrude_edges_indiv(B
                return 0;
        }
  
-       return 'n'; // n is normal grab
+       return 'n';  /* n is normal grab */
  }
  
  /* extrudes individual vertices */
@@@ -295,7 -295,7 +295,7 @@@ static short edbm_extrude_verts_indiv(B
                return 0;
        }
  
-       return 'g'; // g is grab
+       return 'g';  /* g is grab */
  }
  
  static short edbm_extrude_edge(Object *obedit, BMEditMesh *em, const char hflag, float nor[3])
@@@ -1267,11 -1267,11 +1267,11 @@@ static int edbm_vert_connect(bContext *
        }
        else {
                EDBM_selectmode_flush(em);  /* so newly created edges get the selection state from the vertex */
 +      
 +      EDBM_update_generic(C, em, TRUE);
  
 -              EDBM_update_generic(C, em, TRUE);
 -
 -              return len ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
 -      }
 +      return len ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
 +}
  }
  
  void MESH_OT_vert_connect(wmOperatorType *ot)
@@@ -1666,6 -1666,88 +1666,88 @@@ void MESH_OT_vertices_smooth(wmOperator
        RNA_def_boolean(ot->srna, "zaxis", 1, "Z-Axis", "Smooth along the Z axis");
  }
  
+ static int edbm_do_smooth_laplacian_vertex_exec(bContext *C, wmOperator *op)
+ {
+       Object *obedit = CTX_data_edit_object(C);
+       BMEditMesh *em = BMEdit_FromObject(obedit);
+       int usex = TRUE, usey = TRUE, usez = TRUE, volume_preservation = TRUE;
+       int i, repeat;
+       float lambda;
+       float lambda_border;
+       BMIter fiter;
+       BMFace *f;
+       /* Check if select faces are triangles  */
+       BM_ITER_MESH (f, &fiter, em->bm, BM_FACES_OF_MESH) {
+               if (BM_elem_flag_test(f, BM_ELEM_SELECT)) {
+                       if (f->len > 4) {
+                               BKE_report(op->reports, RPT_WARNING, "Selected faces must be triangles or quads");
+                               return OPERATOR_CANCELLED;
+                       }       
+               }
+       }
+       /* mirror before smooth */
+       if (((Mesh *)obedit->data)->editflag & ME_EDIT_MIRROR_X) {
+               EDBM_verts_mirror_cache_begin(em, TRUE);
+       }
+       repeat = RNA_int_get(op->ptr, "repeat");
+       lambda = RNA_float_get(op->ptr, "lambda");
+       lambda_border = RNA_float_get(op->ptr, "lambda_border");
+       usex = RNA_boolean_get(op->ptr, "use_x");
+       usey = RNA_boolean_get(op->ptr, "use_y");
+       usez = RNA_boolean_get(op->ptr, "use_z");
+       volume_preservation = RNA_boolean_get(op->ptr, "volume_preservation");
+       if (!repeat)
+               repeat = 1;
+       
+       for (i = 0; i < repeat; i++) {
+               if (!EDBM_op_callf(em, op,
+                                  "smooth_laplacian_vert verts=%hv lambda=%f lambda_border=%f use_x=%b use_y=%b use_z=%b volume_preservation=%b",
+                                  BM_ELEM_SELECT, lambda, lambda_border, usex, usey, usez, volume_preservation))
+               {
+                       return OPERATOR_CANCELLED;
+               }
+       }
+       /* apply mirror */
+       if (((Mesh *)obedit->data)->editflag & ME_EDIT_MIRROR_X) {
+               EDBM_verts_mirror_apply(em, BM_ELEM_SELECT, 0);
+               EDBM_verts_mirror_cache_end(em);
+       }
+       EDBM_update_generic(C, em, TRUE);
+       return OPERATOR_FINISHED;
+ }
+ void MESH_OT_vertices_smooth_laplacian(wmOperatorType *ot)
+ {
+       /* identifiers */
+       ot->name = "Laplacian Smooth Vertex";
+       ot->description = "Laplacian smooth of selected vertices";
+       ot->idname = "MESH_OT_vertices_smooth_laplacian";
+       
+       /* api callbacks */
+       ot->exec = edbm_do_smooth_laplacian_vertex_exec;
+       ot->poll = ED_operator_editmesh;
+       
+       /* flags */
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+       RNA_def_int(ot->srna, "repeat", 1, 1, 200, 
+                                       "Number of iterations to smooth the mesh", "", 1, 200);
+       RNA_def_float(ot->srna, "lambda", 0.00005f, 0.0000001f, 1000.0f, 
+                                       "Lambda factor", "", 0.0000001f, 1000.0f);
+       RNA_def_float(ot->srna, "lambda_border", 0.00005f, 0.0000001f, 1000.0f, 
+                                       "Lambda factor in border", "", 0.0000001f, 1000.0f);
+       RNA_def_boolean(ot->srna, "use_x", 1, "Smooth X Axis", "Smooth object along     X axis");
+       RNA_def_boolean(ot->srna, "use_y", 1, "Smooth Y Axis", "Smooth object along     Y axis");
+       RNA_def_boolean(ot->srna, "use_z", 1, "Smooth Z Axis", "Smooth object along     Z axis");
+       RNA_def_boolean(ot->srna, "volume_preservation", 1, "Preserve Volume", "Apply volume preservation after smooth");
+ }
  /********************** Smooth/Solid Operators *************************/
  
  static void mesh_set_smooth_faces(BMEditMesh *em, short smooth)
@@@ -2712,21 -2794,21 +2794,21 @@@ static float bm_edge_seg_isect(const fl
                                m1 = MAXSLOPE;
                                b1 = x12;
                        }
-                       x2max = maxf(x21, x22) + 0.001f; /* prevent missed edges   */
-                       x2min = minf(x21, x22) - 0.001f; /* due to round off error */
-                       y2max = maxf(y21, y22) + 0.001f;
-                       y2min = minf(y21, y22) - 0.001f;
+                       x2max = max_ff(x21, x22) + 0.001f; /* prevent missed edges   */
+                       x2min = min_ff(x21, x22) - 0.001f; /* due to round off error */
+                       y2max = max_ff(y21, y22) + 0.001f;
+                       y2min = min_ff(y21, y22) - 0.001f;
                        
                        /* Found an intersect,  calc intersect point */
                        if (m1 == m2) { /* co-incident lines */
                                /* cut at 50% of overlap area */
-                               x1max = maxf(x11, x12);
-                               x1min = minf(x11, x12);
-                               xi = (minf(x2max, x1max) + maxf(x2min, x1min)) / 2.0f;
+                               x1max = max_ff(x11, x12);
+                               x1min = min_ff(x11, x12);
+                               xi = (min_ff(x2max, x1max) + max_ff(x2min, x1min)) / 2.0f;
                                
-                               y1max = maxf(y11, y12);
-                               y1min = minf(y11, y12);
-                               yi = (minf(y2max, y1max) + maxf(y2min, y1min)) / 2.0f;
+                               y1max = max_ff(y11, y12);
+                               y1min = min_ff(y11, y12);
+                               yi = (min_ff(y2max, y1max) + max_ff(y2min, y1min)) / 2.0f;
                        }
                        else if (m2 == MAXSLOPE) {
                                xi = x22;
                                
                                break;
                        }
-               }       
+               }
                lastdist = dist;
        }
        return perc;
@@@ -3412,7 -3494,8 +3494,8 @@@ static int edbm_dissolve_limited_exec(b
        Object *obedit = CTX_data_edit_object(C);
        BMEditMesh *em = BMEdit_FromObject(obedit);
        BMesh *bm = em->bm;
-       float angle_limit = RNA_float_get(op->ptr, "angle_limit");
+       const float angle_limit = RNA_float_get(op->ptr, "angle_limit");
+       const int use_dissolve_boundaries = RNA_boolean_get(op->ptr, "use_dissolve_boundaries");
  
        char dissolve_flag;
  
        }
  
        if (!EDBM_op_callf(em, op,
-                          "dissolve_limit edges=%he verts=%hv angle_limit=%f",
-                          dissolve_flag, dissolve_flag, angle_limit))
+                          "dissolve_limit edges=%he verts=%hv angle_limit=%f use_dissolve_boundaries=%b",
+                          dissolve_flag, dissolve_flag, angle_limit, use_dissolve_boundaries))
        {
                return OPERATOR_CANCELLED;
        }
@@@ -3476,8 -3559,10 +3559,10 @@@ void MESH_OT_dissolve_limited(wmOperato
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
  
        prop = RNA_def_float_rotation(ot->srna, "angle_limit", 0, NULL, 0.0f, DEG2RADF(180.0f),
-                                     "Max Angle", "Angle Limit in Degrees", 0.0f, DEG2RADF(180.0f));
+                                     "Max Angle", "Angle limit", 0.0f, DEG2RADF(180.0f));
        RNA_def_property_float_default(prop, DEG2RADF(15.0f));
+       RNA_def_boolean(ot->srna, "use_dissolve_boundaries", 0, "All Boundaries",
+                       "Dissolve all vertices inbetween face boundaries");
  }
  
  static int edbm_split_exec(bContext *C, wmOperator *op)
@@@ -5147,7 -5232,7 +5232,7 @@@ static int edbm_inset_modal(bContext *C
  
                if (handleNumInput(&opdata->num_input, event)) {
                        applyNumInput(&opdata->num_input, amounts);
-                       amounts[0] = maxf(amounts[0], 0.0f);
+                       amounts[0] = max_ff(amounts[0], 0.0f);
                        RNA_float_set(op->ptr, "thickness", amounts[0]);
                        RNA_float_set(op->ptr, "depth", amounts[1]);
  
                                if (opdata->modify_depth)
                                        RNA_float_set(op->ptr, "depth", amount);
                                else {
-                                       amount = maxf(amount, 0.0f);
+                                       amount = max_ff(amount, 0.0f);
                                        RNA_float_set(op->ptr, "thickness", amount);
                                }
  
@@@ -5386,6 -5471,7 +5471,7 @@@ void MESH_OT_wireframe(wmOperatorType *
        RNA_def_boolean(ot->srna, "use_replace",         TRUE, "Replace", "Remove original faces");
  }
  
+ #ifdef WITH_BULLET
  static int edbm_convex_hull_exec(bContext *C, wmOperator *op)
  {
        Object *obedit = CTX_data_edit_object(C);
@@@ -5479,6 -5565,7 +5565,7 @@@ void MESH_OT_convex_hull(wmOperatorTyp
  
        join_triangle_props(ot);
  }
+ #endif
  
  static int mesh_symmetrize_exec(bContext *C, wmOperator *op)
  {
@@@ -5530,107 -5617,3 +5617,107 @@@ void MESH_OT_symmetrize(struct wmOperat
                                BMO_SYMMETRIZE_NEGATIVE_X,
                                "Direction", "Which sides to copy from and to");
  }
 +
 +static int edbm_mark_freestyle_edge(bContext *C, wmOperator *op)
 +{
 +      Object *obedit = CTX_data_edit_object(C);
 +      Mesh *me = ((Mesh *)obedit->data);
 +      BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh;
 +      BMEdge *eed;
 +      BMIter iter;
 +      int clear = RNA_boolean_get(op->ptr, "clear");
 +
 +      if (em == NULL) return OPERATOR_FINISHED;
 +
 +      /* auto-enable seams drawing */
 +      if (clear == 0) {
 +              me->drawflag |= ME_DRAW_FREESTYLE_EDGE;
 +      }
 +
 +      if (clear) {
 +              BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
 +                      if (BM_elem_flag_test(eed, BM_ELEM_SELECT) && !BM_elem_flag_test(eed, BM_ELEM_HIDDEN))
 +                              BM_elem_flag_disable(eed, BM_ELEM_FREESTYLE);
 +              }
 +      }
 +      else {
 +              BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
 +                      if (BM_elem_flag_test(eed, BM_ELEM_SELECT) && !BM_elem_flag_test(eed, BM_ELEM_HIDDEN))
 +                              BM_elem_flag_enable(eed, BM_ELEM_FREESTYLE);
 +              }
 +      }
 +
 +      DAG_id_tag_update(obedit->data, OB_RECALC_DATA);
 +      WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
 +
 +      return OPERATOR_FINISHED;
 +}
 +
 +void MESH_OT_mark_freestyle_edge(wmOperatorType *ot)
 +{
 +      /* identifiers */
 +      ot->name = "Mark Freestyle Edge";
 +      ot->description = "(un)mark selected edges as Freestyle feature edges";
 +      ot->idname = "MESH_OT_mark_freestyle_edge";
 +
 +      /* api callbacks */
 +      ot->exec = edbm_mark_freestyle_edge;
 +      ot->poll = ED_operator_editmesh;
 +
 +      /* flags */
 +      ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 +
 +      RNA_def_boolean(ot->srna, "clear", 0, "Clear", "");
 +}
 +
 +static int edbm_mark_freestyle_face_exec(bContext *C, wmOperator *op)
 +{
 +      Object *obedit = CTX_data_edit_object(C);
 +      Mesh *me = ((Mesh *)obedit->data);
 +      BMEditMesh *em = ((Mesh *)obedit->data)->edit_btmesh;
 +      BMFace *efa;
 +      BMIter iter;
 +      int clear = RNA_boolean_get(op->ptr, "clear");
 +
 +      if (em == NULL) return OPERATOR_FINISHED;
 +
 +      /* auto-enable Freestyle face mark drawing */
 +      if(!clear) {
 +              me->drawflag |= ME_DRAW_FREESTYLE_FACE;
 +      }
 +
 +      if(clear) {
 +              BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
 +                      if (BM_elem_flag_test(efa, BM_ELEM_SELECT) && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN))
 +                              BM_elem_flag_disable(efa, BM_ELEM_FREESTYLE);
 +              }
 +      } else {
 +              BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
 +                      if (BM_elem_flag_test(efa, BM_ELEM_SELECT) && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN))
 +                              BM_elem_flag_enable(efa, BM_ELEM_FREESTYLE);
 +              }
 +      }
 +
 +      DAG_id_tag_update(obedit->data, OB_RECALC_DATA);
 +      WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
 +
 +      return OPERATOR_FINISHED;
 +}
 +
 +void MESH_OT_mark_freestyle_face(wmOperatorType *ot)
 +{
 +      /* identifiers */
 +      ot->name = "Mark Freestyle Face";
 +      ot->description = "(un)mark selected faces for exclusion from Freestyle feature edge detection";
 +      ot->idname = "MESH_OT_mark_freestyle_face";
 +
 +      /* api callbacks */
 +      ot->exec = edbm_mark_freestyle_face_exec;
 +      ot->poll = ED_operator_editmesh;
 +
 +      /* flags */
 +      ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 +
 +      RNA_def_boolean(ot->srna, "clear", 0, "Clear", "");
 +}
 +
index 835b1ccd52d7b68123db354b1d78404b42a91bed,8b56109202a7e4fb2f890f24300e602a8ccd1b8a..65701663df4a589f613197ad124a794e14676a6e
@@@ -133,8 -133,8 +133,9 @@@ void MESH_OT_select_random(struct wmOpe
  void MESH_OT_loop_multi_select(struct wmOperatorType *ot);
  void MESH_OT_mark_seam(struct wmOperatorType *ot);
  void MESH_OT_mark_sharp(struct wmOperatorType *ot);
 +void MESH_OT_mark_freestyle_edge(struct wmOperatorType *ot);
  void MESH_OT_vertices_smooth(struct wmOperatorType *ot);
+ void MESH_OT_vertices_smooth_laplacian(struct wmOperatorType *ot);
  void MESH_OT_noise(struct wmOperatorType *ot);
  void MESH_OT_flip_normals(struct wmOperatorType *ot);
  void MESH_OT_solidify(struct wmOperatorType *ot);
@@@ -182,7 -182,6 +183,7 @@@ void MESH_OT_rip(struct wmOperatorType 
  void MESH_OT_shape_propagate_to_all(struct wmOperatorType *ot);
  void MESH_OT_blend_from_shape(struct wmOperatorType *ot);
  void MESH_OT_sort_elements(struct wmOperatorType *ot);
 +void MESH_OT_mark_freestyle_face(struct wmOperatorType *ot);
  
  /* ******************* mesh_data.c */
  
index d06142d26544c1b5c79b8102aa327b0373033e00,716af1d938beca6d6a00e304f656929198e364fb..64e61d436eeb68d850e7dbd0e332a62d770014f1
@@@ -118,7 -118,6 +118,7 @@@ void ED_operatortypes_mesh(void
        WM_operatortype_append(MESH_OT_faces_shade_smooth);
        WM_operatortype_append(MESH_OT_faces_shade_flat);
        WM_operatortype_append(MESH_OT_sort_elements);
 +      WM_operatortype_append(MESH_OT_mark_freestyle_face);
  
        WM_operatortype_append(MESH_OT_delete);
        WM_operatortype_append(MESH_OT_edge_collapse);
        WM_operatortype_append(MESH_OT_loop_multi_select);
        WM_operatortype_append(MESH_OT_mark_seam);
        WM_operatortype_append(MESH_OT_mark_sharp);
 +      WM_operatortype_append(MESH_OT_mark_freestyle_edge);
        WM_operatortype_append(MESH_OT_vertices_smooth);
+       WM_operatortype_append(MESH_OT_vertices_smooth_laplacian);
        WM_operatortype_append(MESH_OT_noise);
        WM_operatortype_append(MESH_OT_flip_normals);
        WM_operatortype_append(MESH_OT_rip);
        WM_operatortype_append(MESH_OT_wireframe);
        WM_operatortype_append(MESH_OT_edge_split);
  
+ #ifdef WITH_BULLET
        WM_operatortype_append(MESH_OT_convex_hull);
+ #endif
  
        WM_operatortype_append(MESH_OT_symmetrize);
  
index e5f5a4beac632e31d297f29917664a743def78a0,9c47c407bd9155f12480297dbca6cc7102cb14ba..24e9effa9ebf7b4910038703ebc8382f221e2f7c
@@@ -236,7 -236,7 +236,7 @@@ static int buttons_context_path_materia
                        if (ma) {
                                RNA_id_pointer_create(&ma->id, &path->ptr[path->len]);
                                path->len++;
-                       }                       
+                       }
                        return 1;
                }
        }
@@@ -538,7 -538,6 +538,7 @@@ static int buttons_context_path(const b
        switch (mainb) {
                case BCONTEXT_SCENE:
                case BCONTEXT_RENDER:
 +              case BCONTEXT_RENDER_LAYER:
                        found = buttons_context_path_scene(path);
                        break;
                case BCONTEXT_WORLD:
@@@ -890,7 -889,7 +890,7 @@@ int buttons_context(const bContext *C, 
                else
                        CTX_data_pointer_set(result, NULL, &RNA_ParticleSystem, NULL);
                return 1;
-       }       
+       }
        else if (CTX_data_equals(member, "particle_settings")) {
                /* only available when pinned */
                PointerRNA *ptr = get_pointer_type(path, &RNA_ParticleSettings);
@@@ -1033,7 -1032,7 +1033,7 @@@ void buttons_context_draw(const bContex
                        name = RNA_struct_name_get_alloc(ptr, namebuf, sizeof(namebuf), NULL);
  
                        if (name) {
 -                              if (!ELEM(sbuts->mainb, BCONTEXT_RENDER, BCONTEXT_SCENE) && ptr->type == &RNA_Scene)
 +                              if (!ELEM3(sbuts->mainb, BCONTEXT_RENDER, BCONTEXT_SCENE, BCONTEXT_RENDER_LAYER) && ptr->type == &RNA_Scene)
                                        uiItemLDrag(row, ptr, "", icon);  /* save some space */
                                else
                                        uiItemLDrag(row, ptr, name, icon);
index a24a292be06c93fb9687073f42594b6d103c82d8,09ad73121234c86b8d64cb704e77c59d6a68dacd..7d2374738ef6db6174f93f97c6ea22e13a14bc9f
@@@ -155,8 -155,6 +155,8 @@@ static void buttons_main_area_draw(cons
                ED_region_panels(C, ar, vertical, "scene", sbuts->mainb);
        else if (sbuts->mainb == BCONTEXT_RENDER)
                ED_region_panels(C, ar, vertical, "render", sbuts->mainb);
 +      else if (sbuts->mainb == BCONTEXT_RENDER_LAYER)
 +              ED_region_panels(C, ar, vertical, "render_layer", sbuts->mainb);
        else if (sbuts->mainb == BCONTEXT_WORLD)
                ED_region_panels(C, ar, vertical, "world", sbuts->mainb);
        else if (sbuts->mainb == BCONTEXT_OBJECT)
@@@ -241,7 -239,6 +241,7 @@@ static void buttons_area_listener(ScrAr
                        switch (wmn->data) {
                                case ND_RENDER_OPTIONS:
                                        buttons_area_redraw(sa, BCONTEXT_RENDER);
 +                                      buttons_area_redraw(sa, BCONTEXT_RENDER_LAYER);
                                        break;
                                case ND_FRAME:
                                        /* any buttons area can have animated properties so redraw all */
                                        /* currently works by redraws... if preview is set, it (re)starts job */
                                        sbuts->preview = 1;
                                        break;
-                       }                                       
+                       }
                        break;
                case NC_WORLD:
                        buttons_area_redraw(sa, BCONTEXT_WORLD);
                        ED_area_tag_redraw(sa);
                        sbuts->preview = 1;
                        break;
 +              case NC_LINESTYLE:
 +                      ED_area_tag_redraw(sa);
 +                      sbuts->preview= 1;
 +                      break;
        }
  
        if (wmn->data == ND_KEYS)
index 1408e8b801b0715731af13d813fefc547396da60,7f0af36d5d67d04c6df4359b81ff0adb137fee9a..b505fed7baa49e16b6fac1d10cecd2071780e5d8
@@@ -143,7 -143,8 +143,8 @@@ typedef struct FolderList 
  #define SPECIAL_IMG_FONTFILE 8
  #define SPECIAL_IMG_UNKNOWNFILE 9
  #define SPECIAL_IMG_LOADING 10
- #define SPECIAL_IMG_MAX SPECIAL_IMG_LOADING + 1
+ #define SPECIAL_IMG_BACKUP 11
+ #define SPECIAL_IMG_MAX SPECIAL_IMG_BACKUP + 1
  
  static ImBuf *gSpecialFileImages[SPECIAL_IMG_MAX];
  
@@@ -300,7 -301,7 +301,7 @@@ static int is_hidden_file(const char *f
                        if ( (len > 0) && (filename[len - 1] == '~') ) {
                                is_hidden = 1;  /* ignore file~ */
                        }
-               } 
+               }
        }
        else {
                if (((filename[0] == '.') && (filename[1] == 0) )) {
@@@ -360,7 -361,7 +361,7 @@@ void filelist_filter(FileList *filelist
                struct direntry *file = &filelist->filelist[i];
                if (filelist->filterf(file, filelist->dir, filelist->filter, filelist->hide_dot) ) {
                        num_filtered++;
-               } 
+               }
        }
        
        if (filelist->fidx) {
@@@ -420,7 -421,7 +421,7 @@@ void filelist_free_icons(void
        }
  }
  
- //-----------------FOLDERLIST (previous/next) --------------//
+ /* -----------------FOLDERLIST (previous/next) -------------- */
  ListBase *folderlist_new(void)
  {
        ListBase *p = MEM_callocN(sizeof(ListBase), "folderlist");
@@@ -520,7 -521,7 +521,7 @@@ static void filelist_read_main(struct F
  static void filelist_read_library(struct FileList *filelist);
  static void filelist_read_dir(struct FileList *filelist);
  
- //------------------FILELIST------------------------//
+ /* ------------------FILELIST------------------------ */
  FileList *filelist_new(short type)
  {
        FileList *p = MEM_callocN(sizeof(FileList), "filelist");
@@@ -557,7 -558,7 +558,7 @@@ void filelist_free(struct FileList *fil
        }
  
        for (i = 0; i < filelist->numfiles; ++i) {
-               if (filelist->filelist[i].image) {                      
+               if (filelist->filelist[i].image) {
                        IMB_freeImBuf(filelist->filelist[i].image);
                }
                filelist->filelist[i].image = NULL;
        
        filelist->numfiles = 0;
        free(filelist->filelist);
-       filelist->filelist = NULL;      
+       filelist->filelist = NULL;
        filelist->filter = 0;
        filelist->filter_glob[0] = '\0';
        filelist->numfiltered = 0;
@@@ -683,6 -684,9 +684,9 @@@ ImBuf *filelist_geticon(struct FileLis
        else if (file->flags & IMAGEFILE) {
                ibuf = gSpecialFileImages[SPECIAL_IMG_LOADING];
        }
+       else if (file->flags & BLENDERFILE_BACKUP) {
+               ibuf = gSpecialFileImages[SPECIAL_IMG_BACKUP];
+       }
  
        return ibuf;
  }
@@@ -791,7 -795,7 +795,7 @@@ static int file_extension_type(const ch
                 BLI_testextensie(relname, ".otf") ||
                 BLI_testextensie(relname, ".otc"))
        {
-               return FTFONTFILE;                      
+               return FTFONTFILE;
        }
        else if (BLI_testextensie(relname, ".btx")) {
                return BTXFILE;
        else if (BLI_testextensie_array(relname, imb_ext_image) ||
                 (G.have_quicktime && BLI_testextensie_array(relname, imb_ext_image_qt)))
        {
-               return IMAGEFILE;                       
+               return IMAGEFILE;
        }
        else if (BLI_testextensie_array(relname, imb_ext_movie)) {
-               return MOVIEFILE;                       
+               return MOVIEFILE;
        }
        else if (BLI_testextensie_array(relname, imb_ext_audio)) {
                return SOUNDFILE;
-       } 
+       }
        return 0;
  }
  
@@@ -817,8 -821,10 +821,10 @@@ int ED_file_extension_icon(const char *
  {
        int type = file_extension_type(relname);
        
-       if (type == BLENDERFILE || type == BLENDERFILE_BACKUP)
+       if (type == BLENDERFILE)
                return ICON_FILE_BLEND;
+       else if (type == BLENDERFILE_BACKUP)
+               return ICON_FILE_BACKUP;
        else if (type == IMAGEFILE)
                return ICON_FILE_IMAGE;
        else if (type == MOVIEFILE)
                return ICON_FILE_BLANK;
        else if (type == COLLADAFILE)
                return ICON_FILE_BLANK;
+       else if (type == TEXTFILE)
+               return ICON_FILE_TEXT;
        
        return ICON_FILE_BLANK;
  }
@@@ -934,7 -942,7 +942,7 @@@ void filelist_parent(struct FileList *f
  void filelist_select_file(struct FileList *filelist, int index, FileSelType select, unsigned int flag, FileCheckType check)
  {
        struct direntry *file = filelist_file(filelist, index);
-       if (file != NULL) {     
+       if (file != NULL) {
                int check_ok = 0; 
                switch (check) {
                        case CHECK_DIRS:
@@@ -969,7 -977,7 +977,7 @@@ void filelist_select(struct FileList *f
        /* select all valid files between first and last indicated */
        if ( (sel->first >= 0) && (sel->first < filelist->numfiltered) && (sel->last >= 0) && (sel->last < filelist->numfiltered) ) {
                int current_file;
-               for (current_file = sel->first; current_file <= sel->last; current_file++) {    
+               for (current_file = sel->first; current_file <= sel->last; current_file++) {
                        filelist_select_file(filelist, current_file, select, flag, check);
                }
        }
@@@ -1036,7 -1044,7 +1044,7 @@@ void filelist_from_library(struct FileL
        struct ImBuf *ima;
        int ok, i, nprevs, nnames, idcode;
        char filename[FILE_MAX];
-       char dir[FILE_MAX], group[GROUP_MAX];   
+       char dir[FILE_MAX], group[GROUP_MAX];
        
        /* name test */
        ok = filelist_islibrary(filelist, dir, group);
@@@ -1152,7 -1160,7 +1160,7 @@@ void filelist_from_main(struct FileLis
        if (filelist->dir[0] == 0) {
                
                /* make directories */
 -              filelist->numfiles = 24;
 +              filelist->numfiles = 25;
                filelist->filelist = (struct direntry *)malloc(filelist->numfiles * sizeof(struct direntry));
                
                for (a = 0; a < filelist->numfiles; a++) {
                filelist->filelist[21].relname = BLI_strdup("Action");
                filelist->filelist[22].relname = BLI_strdup("NodeTree");
                filelist->filelist[23].relname = BLI_strdup("Speaker");
 +              filelist->filelist[24].relname= BLI_strdup("FreestyleLineStyle");
                filelist_sort(filelist, FILE_SORT_ALPHA);
        }
        else {
                                                BLI_snprintf(files->relname, FILE_MAX + (MAX_ID_NAME - 2) + 3, "%s | %s", id->lib->name, id->name + 2);
                                        }
                                        files->type |= S_IFREG;
- #if 0               // XXXXX TODO show the selection status of the objects
+ #if 0               /* XXXXX TODO show the selection status of the objects */
                                        if (!filelist->has_func) { /* F4 DATA BROWSE */
                                                if (idcode == ID_OB) {
                                                        if ( ((Object *)id)->flag & SELECT) files->selflag |= SELECTED_FILE;
@@@ -1302,7 -1309,7 +1310,7 @@@ static void thumbnails_startjob(void *t
                if (limg->flags & IMAGEFILE) {
                        limg->img = IMB_thumb_manage(limg->path, THB_NORMAL, THB_SOURCE_IMAGE);
                }
-               else if (limg->flags & BLENDERFILE) {
+               else if (limg->flags & (BLENDERFILE | BLENDERFILE_BACKUP)) {
                        limg->img = IMB_thumb_manage(limg->path, THB_NORMAL, THB_SOURCE_BLEND);
                }
                else if (limg->flags & MOVIEFILE) {
@@@ -1359,7 -1366,7 +1367,7 @@@ void thumbnails_start(struct FileList *
        tj->filelist = filelist;
        for (idx = 0; idx < filelist->numfiles; idx++) {
                if (!filelist->filelist[idx].image) {
-                       if ( (filelist->filelist[idx].flags & (IMAGEFILE | MOVIEFILE | BLENDERFILE)) ) {
+                       if ( (filelist->filelist[idx].flags & (IMAGEFILE | MOVIEFILE | BLENDERFILE | BLENDERFILE_BACKUP)) ) {
                                FileImage *limg = MEM_callocN(sizeof(struct FileImage), "loadimage");
                                BLI_strncpy(limg->path, filelist->filelist[idx].path, FILE_MAX);
                                limg->index = idx;
index badc4dbb53364e728a1dfb94b88bf2ec759ec829,d75946c431757f5ff51df9d7481929d1e92f4cf0..ad6e66f7a7d42e8398fc80a61f2a0ef032ee8cb6
@@@ -71,7 -71,7 +71,7 @@@
  
  static void do_nla_region_buttons(bContext *C, void *UNUSED(arg), int event)
  {
-       //Scene *scene= CTX_data_scene(C);
+       //Scene *scene = CTX_data_scene(C);
        
        switch (event) {
  
@@@ -142,7 -142,6 +142,7 @@@ static int nla_panel_context(const bCon
                        case ANIMTYPE_DSPART:
                        case ANIMTYPE_DSMBALL:
                        case ANIMTYPE_DSARM:
 +                      case ANIMTYPE_DSLINESTYLE:
                        case ANIMTYPE_DSSPK:
                        {
                                /* for these channels, we only do AnimData */
                                                found = -1;
                                        }
                                }
-                       }       
+                       }
                        break;
                }
                
@@@ -243,7 -242,7 +243,7 @@@ static void nla_panel_animdata(const bC
        if (!nla_panel_context(C, &adt_ptr, NULL, NULL))
                return;
  
-       /* adt= adt_ptr.data; */
+       /* adt = adt_ptr.data; */
        
        block = uiLayoutGetBlock(layout);
        uiBlockSetHandleFunc(block, do_nla_region_buttons, NULL);
@@@ -406,7 -405,7 +406,7 @@@ static void nla_panel_evaluation(const 
        uiItemR(col, &strip_ptr, "use_animated_influence", 0, NULL, ICON_NONE);
        
        sub = uiLayoutColumn(col, TRUE);
-       uiLayoutSetEnabled(sub, RNA_boolean_get(&strip_ptr, "use_animated_influence")); 
+       uiLayoutSetEnabled(sub, RNA_boolean_get(&strip_ptr, "use_animated_influence"));
        uiItemR(sub, &strip_ptr, "influence", 0, NULL, ICON_NONE);
  
        col = uiLayoutColumn(layout, TRUE);
index 89a5e9feeefc5552f32cadfa9fa78c5b3bf028d1,95e75d0e4fcfbfba928db7a77d18ffcc223ce8ff..cf56f254c3673725fea32e253d701e692c1beb9c
@@@ -178,7 -178,6 +178,7 @@@ static int mouse_nla_channels(bAnimCont
                case ANIMTYPE_DSMESH:
                case ANIMTYPE_DSTEX:
                case ANIMTYPE_DSLAT:
 +              case ANIMTYPE_DSLINESTYLE:
                case ANIMTYPE_DSSPK:
                {
                        /* sanity checking... */
                        }
                        
                        notifierFlags |= (ND_ANIMCHAN | NA_SELECTED);
-               }       
+               }
                break;
                        
                case ANIMTYPE_NLATRACK:
index ec54ae09fd2d79012ec4a1f219e4b97aef1e782f,04549b53b6a83d6621e2bedb46be78c93125625b..27a660eac2bc16bf95fce96013a43f5604b42ac7
@@@ -126,7 -126,7 +126,7 @@@ typedef struct drawDMEdgesSel_userData 
  } drawDMEdgesSel_userData;
  
  typedef struct drawDMFacesSel_userData {
 -      unsigned char *cols[3];
 +      unsigned char *cols[4];
  
        DerivedMesh *dm; /* BMESH BRANCH ONLY */
        BMEditMesh *em;  /* BMESH BRANCH ONLY */
@@@ -578,7 -578,7 +578,7 @@@ static void draw_empty_image(Object *ob
        glTranslatef(0.0f,  0.0f,  0.0f);
  
        /* Calculate Image scale */
-       scale = (ob->empty_drawsize / (float)MAX2(ima_x * sca_x, ima_y * sca_y));
+       scale = (ob->empty_drawsize / max_ff((float)ima_x * sca_x, (float)ima_y * sca_y));
  
        /* Set the object scale */
        glScalef(scale * sca_x, scale * sca_y, 1.0f);
@@@ -2273,21 -2273,6 +2273,21 @@@ static void draw_dm_edges_sharp(BMEditM
        dm->drawMappedEdges(dm, draw_dm_edges_sharp__setDrawOptions, em);
  }
  
 +/* Draw only Freestyle feature edges */
 +static DMDrawOption draw_dm_edges_freestyle__setDrawOptions(void *userData, int index)
 +{
 +      BMEdge *eed = EDBM_edge_at_index(userData, index);
 +
 +      if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && BM_elem_flag_test(eed, BM_ELEM_FREESTYLE))
 +              return DM_DRAW_OPTION_NORMAL;
 +      else
 +              return DM_DRAW_OPTION_SKIP;
 +}
 +
 +static void draw_dm_edges_freestyle(BMEditMesh *em, DerivedMesh *dm)
 +{
 +      dm->drawMappedEdges(dm, draw_dm_edges_freestyle__setDrawOptions, em);
 +}
  
  /* Draw faces with color set based on selection
   * return 2 for the active face so it renders with stipple enabled */
@@@ -2302,11 -2287,11 +2302,11 @@@ static DMDrawOption draw_dm_faces_sel__
        
        if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
                if (efa == data->efa_act) {
 -                      glColor4ubv(data->cols[2]);
 +                      glColor4ubv(data->cols[3]);
                        return DM_DRAW_OPTION_STIPPLE;
                }
                else {
 -                      col = data->cols[BM_elem_flag_test(efa, BM_ELEM_SELECT) ? 1 : 0];
 +                      col = data->cols[BM_elem_flag_test(efa, BM_ELEM_SELECT) ? 1 : BM_elem_flag_test(efa, BM_ELEM_FREESTYLE) ? 2 : 0];
                        if (col[3] == 0)
                                return DM_DRAW_OPTION_SKIP;
                        glColor4ubv(col);
@@@ -2337,8 -2322,8 +2337,8 @@@ static int draw_dm_faces_sel__compareDr
        if (efa == data->efa_act || next_efa == data->efa_act)
                return 0;
  
 -      col = data->cols[BM_elem_flag_test(efa, BM_ELEM_SELECT) ? 1 : 0];
 -      next_col = data->cols[BM_elem_flag_test(next_efa, BM_ELEM_SELECT) ? 1 : 0];
 +      col = data->cols[BM_elem_flag_test(efa, BM_ELEM_SELECT) ? 1 : BM_elem_flag_test(efa, BM_ELEM_FREESTYLE) ? 2 : 0];
 +      next_col = data->cols[BM_elem_flag_test(next_efa, BM_ELEM_SELECT) ? 1 : BM_elem_flag_test(next_efa, BM_ELEM_FREESTYLE) ? 2 : 0];
  
        if (col[3] == 0 || next_col[3] == 0)
                return 0;
  
  /* also draws the active face */
  static void draw_dm_faces_sel(BMEditMesh *em, DerivedMesh *dm, unsigned char *baseCol,
 -                              unsigned char *selCol, unsigned char *actCol, BMFace *efa_act)
 +                              unsigned char *selCol, unsigned char *markCol, unsigned char *actCol, BMFace *efa_act)
  {
        drawDMFacesSel_userData data;
        data.dm = dm;
        data.cols[0] = baseCol;
        data.em = em;
        data.cols[1] = selCol;
 -      data.cols[2] = actCol;
 +      data.cols[2] = markCol;
 +      data.cols[3] = actCol;
        data.efa_act = efa_act;
        data.orig_index = DM_get_tessface_data_layer(dm, CD_ORIGINDEX);
  
@@@ -2888,12 -2872,11 +2888,12 @@@ static void draw_em_fancy(Scene *scene
        }
        
        if (me->drawflag & ME_DRAWFACES) {  /* transp faces */
 -              unsigned char col1[4], col2[4], col3[4];
 +              unsigned char col1[4], col2[4], col3[4], col4[4];
  
                UI_GetThemeColor4ubv(TH_FACE, col1);
                UI_GetThemeColor4ubv(TH_FACE_SELECT, col2);
 -              UI_GetThemeColor4ubv(TH_EDITMESH_ACTIVE, col3);
 +              UI_GetThemeColor4ubv(TH_FREESTYLE_FACE_MARK, col3);
 +              UI_GetThemeColor4ubv(TH_EDITMESH_ACTIVE, col4);
  
                glEnable(GL_BLEND);
                glDepthMask(0);  /* disable write in zbuffer, needed for nice transp */
                if (check_object_draw_texture(scene, v3d, dt))
                        col1[3] = 0;
  
 -              draw_dm_faces_sel(em, cageDM, col1, col2, col3, efa_act);
 +              if (!(me->drawflag & ME_DRAW_FREESTYLE_FACE))
 +                      col3[3] = 0;
 +
 +              draw_dm_faces_sel(em, cageDM, col1, col2, col3, col4, efa_act);
  
                glDisable(GL_BLEND);
                glDepthMask(1);  /* restore write in zbuffer */
                /* even if draw faces is off it would be nice to draw the stipple face
                 * Make all other faces zero alpha except for the active
                 * */
 -              unsigned char col1[4], col2[4], col3[4];
 -              col1[3] = col2[3] = 0; /* don't draw */
 -              UI_GetThemeColor4ubv(TH_EDITMESH_ACTIVE, col3);
 +              unsigned char col1[4], col2[4], col3[4], col4[4];
 +              col1[3] = col2[3] = col3[3] = 0; /* don't draw */
 +              UI_GetThemeColor4ubv(TH_EDITMESH_ACTIVE, col4);
  
                glEnable(GL_BLEND);
                glDepthMask(0);  /* disable write in zbuffer, needed for nice transp */
  
 -              draw_dm_faces_sel(em, cageDM, col1, col2, col3, efa_act);
 +              draw_dm_faces_sel(em, cageDM, col1, col2, col3, col4, efa_act);
  
                glDisable(GL_BLEND);
                glDepthMask(1);  /* restore write in zbuffer */
                        glLineWidth(1);
                }
  
 +              if(me->drawflag & ME_DRAW_FREESTYLE_EDGE) {
 +                      UI_ThemeColor(TH_FREESTYLE_EDGE_MARK);
 +                      glLineWidth(2);
 +      
 +                      draw_dm_edges_freestyle(em, cageDM);
 +      
 +                      glColor3ub(0,0,0);
 +                      glLineWidth(1);
 +              }
 +      
                if (me->drawflag & ME_DRAWCREASES && CustomData_has_layer(&em->bm->edata, CD_CREASE)) {
                        draw_dm_creases(em, cageDM);
                }
@@@ -4457,7 -4427,7 +4457,7 @@@ static void draw_new_particle_system(Sc
  
                if (cdata2)
                        MEM_freeN(cdata2);
-               /* cd2= */ /* UNUSED */ cdata2 = NULL;
+               /* cd2 = */ /* UNUSED */ cdata2 = NULL;
  
                glLineWidth(1.0f);
  
@@@ -5523,7 -5493,7 +5523,7 @@@ static void drawcircle_size(float size
  
        glBegin(GL_LINE_LOOP);
  
-       /* coordinates are: cos(degrees*11.25)=x, sin(degrees*11.25)=y, 0.0f=z */
+       /* coordinates are: cos(degrees * 11.25) = x, sin(degrees*11.25) = y, 0.0f = z */
        for (degrees = 0; degrees < CIRCLE_RESOL; degrees++) {
                x = cosval[degrees];
                y = sinval[degrees];
@@@ -6570,7 -6540,6 +6570,6 @@@ void draw_object(Scene *scene, ARegion 
        /* code for new particle system */
        if ((warning_recursive == 0) &&
            (ob->particlesystem.first) &&
-           (dflag & DRAW_PICKING) == 0 &&
            (ob != scene->obedit)
            )
        {
index 4a61978cc8000603b74af0f23e82175b94fe5c7f,e555d1bb46354ba3950a224633d84786e3fc00aa..1537b4f61ce7051fb9d9bfe1aa5494ed98b95b77
@@@ -277,7 -277,7 +277,7 @@@ void projectIntView(TransInfo *t, cons
                        //vec[0] = vec[0]/((t->scene->r.frs_sec / t->scene->r.frs_sec_base));
                        /* same as below */
                        UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out + 1);
-               } 
+               }
                else
  #endif
                {
@@@ -469,11 -469,11 +469,11 @@@ static void viewRedrawForce(const bCont
                
        }
        else if (t->spacetype == SPACE_ACTION) {
-               //SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first;
+               //SpaceAction *saction = (SpaceAction *)t->sa->spacedata.first;
                WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
        }
        else if (t->spacetype == SPACE_IPO) {
-               //SpaceIpo *sipo= (SpaceIpo *)t->sa->spacedata.first;
+               //SpaceIpo *sipo = (SpaceIpo *)t->sa->spacedata.first;
                WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
        }
        else if (t->spacetype == SPACE_NLA) {
@@@ -832,6 -832,9 +832,6 @@@ int transformEvent(TransInfo *t, wmEven
        t->redraw |= handleMouseInput(t, &t->mouse, event);
  
        if (event->type == MOUSEMOVE) {
 -              if (t->modifiers & MOD_CONSTRAINT_SELECT)
 -                      t->con.mode |= CON_SELECT;
 -
                copy_v2_v2_int(t->mval, event->mval);
  
                // t->redraw |= TREDRAW_SOFT; /* Use this for soft redraw. Might cause flicker in object mode */
                                if (t->flag & T_PROP_EDIT) {
                                        t->prop_size *= 1.1f;
                                        if (t->spacetype == SPACE_VIEW3D && t->persp != RV3D_ORTHO)
-                                               t->prop_size = minf(t->prop_size, ((View3D *)t->view)->far);
+                                               t->prop_size = min_ff(t->prop_size, ((View3D *)t->view)->far);
                                        calculatePropRatio(t);
                                }
                                t->redraw |= TREDRAW_HARD;
                                if (event->alt && t->flag & T_PROP_EDIT) {
                                        t->prop_size *= 1.1f;
                                        if (t->spacetype == SPACE_VIEW3D && t->persp != RV3D_ORTHO)
-                                               t->prop_size = minf(t->prop_size, ((View3D *)t->view)->far);
+                                               t->prop_size = min_ff(t->prop_size, ((View3D *)t->view)->far);
                                        calculatePropRatio(t);
                                }
                                t->redraw = 1;
                        }
                }
        }
+       else
+               handled = 0;
  
        // Per transform event, if present
        if (t->handleEvent)
@@@ -1484,8 -1489,8 +1486,8 @@@ static void drawHelpline(bContext *UNUS
                                float dx = t->mval[0] - cent[0], dy = t->mval[1] - cent[1];
                                float angle = atan2f(dy, dx);
                                float dist = sqrtf(dx * dx + dy * dy);
-                               float delta_angle = minf(15.0f / dist, (float)M_PI / 4.0f);
-                               float spacing_angle = minf(5.0f / dist, (float)M_PI / 12.0f);
+                               float delta_angle = min_ff(15.0f / dist, (float)M_PI / 4.0f);
+                               float spacing_angle = min_ff(5.0f / dist, (float)M_PI / 12.0f);
                                UI_ThemeColor(TH_WIRE);
  
                                setlinestyle(3);
@@@ -1598,8 -1603,10 +1600,10 @@@ static void drawTransformPixel(const st
         */
        if ((U.autokey_flag & AUTOKEY_FLAG_NOWARNING) == 0) {
                if (ar == t->ar) {
-                       if (ob && autokeyframe_cfra_can_key(scene, &ob->id)) {
-                               drawAutoKeyWarning(t, ar);
+                       if (t->flag & (T_OBJECT | T_POSE)) {
+                               if (ob && autokeyframe_cfra_can_key(scene, &ob->id)) {
+                                       drawAutoKeyWarning(t, ar);
+                               }
                        }
                }
        }
@@@ -2013,9 -2020,6 +2017,9 @@@ void transformApply(bContext *C, TransI
        t->context = C;
  
        if ((t->redraw & TREDRAW_HARD) || (t->draw_handle_apply == NULL && (t->redraw & TREDRAW_SOFT))) {
 +              if (t->modifiers & MOD_CONSTRAINT_SELECT)
 +                      t->con.mode |= CON_SELECT;
 +
                selectConstraint(t);
                if (t->transform) {
                        t->transform(t, t->mval);  // calls recalcData()
@@@ -3383,7 -3387,7 +3387,7 @@@ static void ElementRotation(TransInfo *
                                /* this function works on end result */
                                protectedAxisAngleBits(td->protectflag, td->ext->rotAxis, td->ext->rotAngle, td->ext->irotAxis, td->ext->irotAngle);
                        }
-                       else { 
+                       else {
                                float eulmat[3][3];
                                
                                mul_m3_m3m3(totmat, mat, td->ext->r_mtx);
@@@ -4811,7 -4815,7 +4815,7 @@@ static BMLoop *get_next_loop(BMVert *v
                }
                
                l = l->radial_next;
-       } while (l != firstl); 
+       } while (l != firstl);
  
        if (i)
                mul_v3_fl(a, 1.0f / (float)i);
@@@ -5612,7 -5616,7 +5616,7 @@@ static int doEdgeSlide(TransInfo *t, fl
  
                for (i = 0; i < sld->totsv; i++, sv++) {
                        const float sv_length = len_v3v3(sv->up->co, sv->down->co);
-                       const float fac = minf(sv_length, curr_length_perc) / sv_length;
+                       const float fac = min_ff(sv_length, curr_length_perc) / sv_length;
  
                        if (sld->flipped_vtx) {
                                interp_v3_v3v3(sv->v->co, sv->down->co, sv->up->co, fac);
@@@ -6108,7 -6112,7 +6112,7 @@@ static short getAnimEdit_DrawTime(Trans
                SpaceIpo *sipo = (SpaceIpo *)t->sa->spacedata.first;
                
                drawtime = (sipo->flag & SIPO_DRAWTIME) ? 1 : 0;
-       }       
+       }
        else {
                drawtime = 0;
        }
@@@ -6589,5 -6593,5 +6593,5 @@@ int TimeScale(TransInfo *t, const int U
  void BIF_TransformSetUndo(const char *UNUSED(str))
  {
        // TRANSFORM_FIX_ME
-       //Trans.undostr= str;
+       //Trans.undostr = str;
  }
index 09451754deebd8152018a21550d302b2f4a34f8c,9a8d3bf981c992fb146c5c44caf34aedacee015d..11b93b5fefe80914458d63e836c3e6fa36966ed1
@@@ -86,7 -86,7 +86,7 @@@ typedef struct Material 
        ID id;
        struct AnimData *adt;   /* animation data (must be immediately after id for utilities to use it) */ 
        
-       short material_type, flag;      
+       short material_type, flag;
        /* note, keep this below synced with render_types.h */
        float r, g, b;
        float specr, specg, specb;
        float rampfac_col, rampfac_spec;
  
        struct MTex *mtex[18];          /* MAX_MTEX */
-       struct bNodeTree *nodetree;     
+       struct bNodeTree *nodetree;
        struct Ipo *ipo  DNA_DEPRECATED;  /* old animation system, deprecated for 2.5 */
        struct Group *group;    /* light group */
        struct PreviewImage *preview;
        short shadowonly_flag;  /* "shadowsonly" type */
        short index;            /* custom index for render passes */
  
 +      short vcol_alpha;
 +      short pad4[3];
 +
        ListBase gpumaterial;           /* runtime */
  } Material;
  
index f28c0328acc47630c0cc78e3cb003756856960d4,0c193e9be210f9e9451950c86d4e92ea6c2d0484..bdb1568c73f2e5a63024654614e789e1ad3a7b5e
@@@ -72,7 -72,7 +72,7 @@@ typedef struct MVert 
   * at the moment alpha is abused for vertex painting
   * and not used for transparency, note that red and blue are swapped */
  typedef struct MCol {
-       char a, r, g, b;        
+       char a, r, g, b;
  } MCol;
  
  /* new face structure, replaces MFace, which is now
@@@ -290,7 -290,6 +290,7 @@@ typedef struct MVertSkin 
  #define ME_LOOSEEDGE          (1<<7)
  /* #define ME_SEAM_LAST               (1<<8) */ /* UNUSED */
  #define ME_SHARP                      (1<<9)    /* only reason this flag remains a 'short' */
 +#define ME_FREESTYLE_EDGE     (1<<10)
  
  /* puno = vertexnormal (mface) */
  #define ME_PROJXY             16
  /* flag (mface) */
  #define ME_SMOOTH                     1
  #define ME_FACE_SEL                   2
 +#define ME_FREESTYLE_FACE     4
  /* flag ME_HIDE==16 is used here too */ 
  
  #define ME_POLY_LOOP_PREV(mloop, mp, i)  (&(mloop)[(mp)->loopstart + (((i) + (mp)->totloop - 1) % (mp)->totloop)])
index 2aab702add034bbd54267a1d9f594c4f27061362,9d59817632a40106018aff7f5f5a31f6ac1a8ce4..9bfa0e7fdf7094b9b5e3eff15c5a6b15bb63d775
@@@ -45,7 -45,6 +45,7 @@@ extern "C" 
  #include "DNA_vec_types.h"
  #include "DNA_listBase.h"
  #include "DNA_ID.h"
 +#include "DNA_freestyle_types.h"
  
  struct Object;
  struct Brush;
@@@ -188,9 -187,6 +188,9 @@@ typedef struct SceneRenderLayer 
  
        int samples;
        int pad;
 +      
 +      struct FreestyleConfig freestyleConfig;
 +      
  } SceneRenderLayer;
  
  /* srl->layflag */
  #define SCE_LAY_EDGE  8
  #define SCE_LAY_SKY           16
  #define SCE_LAY_STRAND        32
 -      /* flags between 32 and 0x8000 are set to 1 already, for future options */
 +#define SCE_LAY_FRS           64
 +      /* flags between 64 and 0x8000 are set to 1 already, for future options */
  
  #define SCE_LAY_ALL_Z         0x8000
  #define SCE_LAY_XOR                   0x10000
@@@ -323,10 -318,11 +323,11 @@@ typedef struct ImageFormatData 
  /* return values from BKE_imtype_valid_depths, note this is depts per channel */
  #define R_IMF_CHAN_DEPTH_1  (1<<0) /* 1bits  (unused) */
  #define R_IMF_CHAN_DEPTH_8  (1<<1) /* 8bits  (default) */
- #define R_IMF_CHAN_DEPTH_12 (1<<2) /* 12bits (uncommon, jp2 supports) */
- #define R_IMF_CHAN_DEPTH_16 (1<<3) /* 16bits (tiff, halff float exr) */
- #define R_IMF_CHAN_DEPTH_24 (1<<4) /* 24bits (unused) */
- #define R_IMF_CHAN_DEPTH_32 (1<<5) /* 32bits (full float exr) */
+ #define R_IMF_CHAN_DEPTH_10 (1<<2) /* 10bits (uncommon, Cineon/DPX support) */
+ #define R_IMF_CHAN_DEPTH_12 (1<<3) /* 12bits (uncommon, jp2/DPX support) */
+ #define R_IMF_CHAN_DEPTH_16 (1<<4) /* 16bits (tiff, halff float exr) */
+ #define R_IMF_CHAN_DEPTH_24 (1<<5) /* 24bits (unused) */
+ #define R_IMF_CHAN_DEPTH_32 (1<<6) /* 32bits (full float exr) */
  
  /* ImageFormatData.planes */
  #define R_IMF_PLANES_RGB   24
@@@ -480,7 -476,7 +481,7 @@@ typedef struct RenderData 
        int color_mgt_flag;
        
        /** post-production settings. deprecated, but here for upwards compat (initialized to 1) */
-       float postgamma, posthue, postsat;       
+       float postgamma, posthue, postsat;
        
         /* Dither noise intensity */
        float dither_intensity;
        float pad2;
        struct Text *dometext  DNA_DEPRECATED;  //  XXX deprecated since 2.5
  
 +      /* Freestyle line thickness options */
 +      int line_thickness_mode;
 +      float unit_line_thickness; /* in pixels */
 +
        /* render engine */
        char engine[32];
  } RenderData;
@@@ -1095,7 -1087,7 +1096,7 @@@ typedef struct Scene 
        
        short use_nodes;
        
-       struct bNodeTree *nodetree;     
+       struct bNodeTree *nodetree;
        
        struct Editing *ed;                                                             /* sequence editor data is allocated here */
        
  #define R_NO_OVERWRITE        0x400000 /* skip existing files */
  #define R_TOUCH                       0x800000 /* touch files before rendering */
  #define R_SIMPLIFY            0x1000000
 +#define R_EDGE_FRS            0x2000000 /* R_EDGE for Freestyle */
  
  /* seq_flag */
  #define R_SEQ_GL_PREV 1
- #define R_SEQ_GL_REND 2
+ // #define R_SEQ_GL_REND 2  // UNUSED, opengl render has its own operator now.
  
  /* displaymode */
  
  /* simplify_flag */
  #define R_SIMPLE_NO_TRIANGULATE               1
  
 +/* line_thickness_mode */
 +#define R_LINE_THICKNESS_ABSOLUTE 1
 +#define R_LINE_THICKNESS_RELATIVE 2
 +
  /* sequencer seq_prev_type seq_rend_type */
  
  
  /* **************** SCENE ********************* */
  
  /* for general use */
  #define       SFRA                    (scene->r.sfra)
  #define       EFRA                    (scene->r.efra)
  #define PRVRANGEON            (scene->r.flag & SCER_PRV_RANGE)
- #define PSFRA                 ((PRVRANGEON)? (scene->r.psfra): (scene->r.sfra))
- #define PEFRA                 ((PRVRANGEON)? (scene->r.pefra): (scene->r.efra))
+ #define PSFRA                 ((PRVRANGEON) ? (scene->r.psfra) : (scene->r.sfra))
+ #define PEFRA                 ((PRVRANGEON) ? (scene->r.pefra) : (scene->r.efra))
  #define FRA2TIME(a)           ((((double) scene->r.frs_sec_base) * (double)(a)) / (double)scene->r.frs_sec)
  #define TIME2FRA(a)           ((((double) scene->r.frs_sec) * (double)(a)) / (double)scene->r.frs_sec_base)
  #define FPS                     (((double) scene->r.frs_sec) / (double)scene->r.frs_sec_base)
@@@ -1466,6 -1454,7 +1468,7 @@@ typedef enum SculptFlags 
        SCULPT_SYMMETRY_FEATHER = (1<<6),
        SCULPT_USE_OPENMP = (1<<7),
        SCULPT_ONLY_DEFORM = (1<<8),
+       SCULPT_SHOW_DIFFUSE = (1<<9),
  } SculptFlags;
  
  /* ImagePaintSettings.flag */
  #define EDGE_MODE_TAG_SHARP                           2
  #define EDGE_MODE_TAG_CREASE                  3
  #define EDGE_MODE_TAG_BEVEL                           4
 +#define EDGE_MODE_TAG_FREESTYLE                       5
  
  /* toolsettings->gpencil_flags */
  #define GP_TOOL_FLAG_PAINTSESSIONS_ON (1<<0)
index 9289d140b85381149848251a7a8b2ed958ccdd43,be6464778e533f35b0b81edb31751c2af7b2817c..408dc17c6a02cef98161752c4a91afa33d972a5d
+++ b/