Revert to master - those changes are globally valid, but remain incomplete,
[blender.git] / source / blender / makesrna / intern / rna_main_api.c
index a2f9b554d3f7d12a31619f2d8f431cfd7c041300..5a0da0b76517fa9c2ac9f010d1c27c908703fabb 100644 (file)
@@ -35,6 +35,8 @@
 
 #include "DNA_ID.h"
 #include "DNA_modifier_types.h"
+#include "DNA_space_types.h"
+#include "DNA_object_types.h"
 
 #include "BLI_utildefines.h"
 #include "BLI_path_util.h"
 #include "BKE_library.h"
 #include "BKE_object.h"
 #include "BKE_material.h"
+#include "BKE_icons.h"
 #include "BKE_image.h"
 #include "BKE_texture.h"
 #include "BKE_scene.h"
+#include "BKE_sound.h"
 #include "BKE_text.h"
 #include "BKE_action.h"
 #include "BKE_group.h"
@@ -69,6 +73,7 @@
 #include "BKE_mball.h"
 #include "BKE_world.h"
 #include "BKE_particle.h"
+#include "BKE_paint.h"
 #include "BKE_font.h"
 #include "BKE_node.h"
 #include "BKE_depsgraph.h"
@@ -84,8 +89,8 @@
 #include "DNA_lamp_types.h"
 #include "DNA_material_types.h"
 #include "DNA_mesh_types.h"
-#include "DNA_object_types.h"
 #include "DNA_speaker_types.h"
+#include "DNA_sound_types.h"
 #include "DNA_text_types.h"
 #include "DNA_texture_types.h"
 #include "DNA_group_types.h"
 
 #include "ED_screen.h"
 
-#include "BLF_translation.h"
+#include "BLT_translation.h"
+
+#ifdef WITH_PYTHON
+#  include "BPY_extern.h"
+#endif
 
 static Camera *rna_Main_cameras_new(Main *bmain, const char *name)
 {
@@ -114,7 +123,7 @@ static void rna_Main_cameras_remove(Main *bmain, ReportList *reports, PointerRNA
 {
        Camera *camera = camera_ptr->data;
        if (ID_REAL_USERS(camera) <= 0) {
-               BKE_libblock_free(&bmain->camera, camera);
+               BKE_libblock_free(bmain, camera);
                RNA_POINTER_INVALIDATE(camera_ptr);
        }
        else {
@@ -138,7 +147,17 @@ static void rna_Main_scenes_remove(Main *bmain, bContext *C, ReportList *reports
        {
                bScreen *sc = CTX_wm_screen(C);
                if (sc->scene == scene) {
+
+#ifdef WITH_PYTHON
+                       BPy_BEGIN_ALLOW_THREADS;
+#endif
+
                        ED_screen_set_scene(C, sc, scene_new);
+
+#ifdef WITH_PYTHON
+                       BPy_END_ALLOW_THREADS;
+#endif
+
                }
 
                BKE_scene_unlink(bmain, scene, scene_new);
@@ -198,7 +217,7 @@ static Object *rna_Main_objects_new(Main *bmain, ReportList *reports, const char
        id_us_min(&ob->id);
 
        ob->data = data;
-       test_object_materials(ob->data);
+       test_object_materials(bmain, ob->data);
        
        return ob;
 }
@@ -208,7 +227,7 @@ static void rna_Main_objects_remove(Main *bmain, ReportList *reports, PointerRNA
        Object *object = object_ptr->data;
        if (ID_REAL_USERS(object) <= 0) {
                BKE_object_unlink(object); /* needed or ID pointers to this are not cleared */
-               BKE_libblock_free(&bmain->object, object);
+               BKE_libblock_free(bmain, object);
                RNA_POINTER_INVALIDATE(object_ptr);
        }
        else {
@@ -227,7 +246,7 @@ static void rna_Main_materials_remove(Main *bmain, ReportList *reports, PointerR
 {
        Material *material = material_ptr->data;
        if (ID_REAL_USERS(material) <= 0) {
-               BKE_libblock_free(&bmain->mat, material);
+               BKE_libblock_free(bmain, material);
                RNA_POINTER_INVALIDATE(material_ptr);
        }
        else {
@@ -236,9 +255,9 @@ static void rna_Main_materials_remove(Main *bmain, ReportList *reports, PointerR
        }
 }
 
-static EnumPropertyItem *rna_Main_nodetree_type_itemf(bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free)
+static EnumPropertyItem *rna_Main_nodetree_type_itemf(bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
 {
-       return rna_node_tree_type_itemf(NULL, NULL, free);
+       return rna_node_tree_type_itemf(NULL, NULL, r_free);
 }
 static struct bNodeTree *rna_Main_nodetree_new(Main *bmain, const char *name, int type)
 {
@@ -256,7 +275,7 @@ static void rna_Main_nodetree_remove(Main *bmain, ReportList *reports, PointerRN
 {
        bNodeTree *ntree = ntree_ptr->data;
        if (ID_REAL_USERS(ntree) <= 0) {
-               BKE_libblock_free(&bmain->nodetree, ntree);
+               BKE_libblock_free(bmain, ntree);
                RNA_POINTER_INVALIDATE(ntree_ptr);
        }
        else {
@@ -276,205 +295,28 @@ static Mesh *rna_Main_meshes_new(Main *bmain, const char *name)
 /* settings: 1 - preview, 2 - render */
 Mesh *rna_Main_meshes_new_from_object(
         Main *bmain, ReportList *reports, Scene *sce,
-        Object *ob, int apply_modifiers, int settings, int calc_tessface)
+        Object *ob, int apply_modifiers, int settings, int calc_tessface, int calc_undeformed)
 {
-       Mesh *tmpmesh;
-       Curve *tmpcu = NULL, *copycu;
-       Object *tmpobj = NULL;
-       int render = settings == eModifierMode_Render, i;
-       int cage = !apply_modifiers;
-
-       /* perform the mesh extraction based on type */
        switch (ob->type) {
                case OB_FONT:
                case OB_CURVE:
                case OB_SURF:
-               {
-                       ListBase dispbase = {NULL, NULL};
-                       DerivedMesh *derivedFinal = NULL;
-                       int uv_from_orco;
-
-                       /* copies object and modifiers (but not the data) */
-                       tmpobj = BKE_object_copy_ex(bmain, ob, TRUE);
-                       tmpcu = (Curve *)tmpobj->data;
-                       tmpcu->id.us--;
-
-                       /* if getting the original caged mesh, delete object modifiers */
-                       if (cage)
-                               BKE_object_free_modifiers(tmpobj);
-
-                       /* copies the data */
-                       copycu = tmpobj->data = BKE_curve_copy((Curve *) ob->data);
-
-                       /* temporarily set edit so we get updates from edit mode, but
-                        * also because for text datablocks copying it while in edit
-                        * mode gives invalid data structures */
-                       copycu->editfont = tmpcu->editfont;
-                       copycu->editnurb = tmpcu->editnurb;
-
-                       /* get updated display list, and convert to a mesh */
-                       BKE_displist_make_curveTypes_forRender(sce, tmpobj, &dispbase, &derivedFinal, FALSE, render);
-
-                       copycu->editfont = NULL;
-                       copycu->editnurb = NULL;
-
-                       tmpobj->derivedFinal = derivedFinal;
-
-                       /* convert object type to mesh */
-                       uv_from_orco = (tmpcu->flag & CU_UV_ORCO) != 0;
-                       BKE_mesh_from_nurbs_displist(tmpobj, &dispbase, uv_from_orco);
-
-                       tmpmesh = tmpobj->data;
-
-                       BKE_displist_free(&dispbase);
-
-                       /* BKE_mesh_from_nurbs changes the type to a mesh, check it worked */
-                       if (tmpobj->type != OB_MESH) {
-                               BKE_libblock_free_us(&(G.main->object), tmpobj);
-                               BKE_report(reports, RPT_ERROR, "Cannot convert curve to mesh (does the curve have any segments?)");
-                               return NULL;
-                       }
-
-                       BKE_libblock_free_us(&bmain->object, tmpobj);
-                       break;
-               }
-
                case OB_MBALL:
-               {
-                       /* metaballs don't have modifiers, so just convert to mesh */
-                       Object *basis_ob = BKE_mball_basis_find(sce, ob);
-                       /* todo, re-generatre for render-res */
-                       /* metaball_polygonize(scene, ob) */
-
-                       if (ob != basis_ob)
-                               return NULL;  /* only do basis metaball */
-
-                       tmpmesh = BKE_mesh_add(bmain, "Mesh");
-                       /* BKE_mesh_add gives us a user count we don't need */
-                       tmpmesh->id.us--;
-
-                       if (render) {
-                               ListBase disp = {NULL, NULL};
-                               BKE_displist_make_mball_forRender(sce, ob, &disp);
-                               BKE_mesh_from_metaball(&disp, tmpmesh);
-                               BKE_displist_free(&disp);
-                       }
-                       else
-                               BKE_mesh_from_metaball(&ob->disp, tmpmesh);
-
-                       break;
-
-               }
                case OB_MESH:
-                       /* copies object and modifiers (but not the data) */
-                       if (cage) {
-                               /* copies the data */
-                               tmpmesh = BKE_mesh_copy_ex(bmain, ob->data);
-                               /* if not getting the original caged mesh, get final derived mesh */
-                       }
-                       else {
-                               /* Make a dummy mesh, saves copying */
-                               DerivedMesh *dm;
-                               /* CustomDataMask mask = CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL; */
-                               CustomDataMask mask = CD_MASK_MESH; /* this seems more suitable, exporter,
-                                                                * for example, needs CD_MASK_MDEFORMVERT */
-
-                               /* Write the display mesh into the dummy mesh */
-                               if (render)
-                                       dm = mesh_create_derived_render(sce, ob, mask);
-                               else
-                                       dm = mesh_create_derived_view(sce, ob, mask);
-
-                               tmpmesh = BKE_mesh_add(bmain, "Mesh");
-                               DM_to_mesh(dm, tmpmesh, ob);
-                               dm->release(dm);
-                       }
-
-                       /* BKE_mesh_add/copy gives us a user count we don't need */
-                       tmpmesh->id.us--;
-
                        break;
                default:
                        BKE_report(reports, RPT_ERROR, "Object does not have geometry data");
                        return NULL;
        }
 
-       /* Copy materials to new mesh */
-       switch (ob->type) {
-               case OB_SURF:
-               case OB_FONT:
-               case OB_CURVE:
-                       tmpmesh->totcol = tmpcu->totcol;
-
-                       /* free old material list (if it exists) and adjust user counts */
-                       if (tmpcu->mat) {
-                               for (i = tmpcu->totcol; i-- > 0; ) {
-                                       /* are we an object material or data based? */
-
-                                       tmpmesh->mat[i] = ob->matbits[i] ? ob->mat[i] : tmpcu->mat[i];
-
-                                       if (tmpmesh->mat[i]) {
-                                               tmpmesh->mat[i]->id.us++;
-                                       }
-                               }
-                       }
-                       break;
-
-#if 0
-               /* Crashes when assigning the new material, not sure why */
-               case OB_MBALL:
-                       tmpmb = (MetaBall *)ob->data;
-                       tmpmesh->totcol = tmpmb->totcol;
-
-                       /* free old material list (if it exists) and adjust user counts */
-                       if (tmpmb->mat) {
-                               for (i = tmpmb->totcol; i-- > 0; ) {
-                                       tmpmesh->mat[i] = tmpmb->mat[i]; /* CRASH HERE ??? */
-                                       if (tmpmesh->mat[i]) {
-                                               tmpmb->mat[i]->id.us++;
-                                       }
-                               }
-                       }
-                       break;
-#endif
-
-               case OB_MESH:
-                       if (!cage) {
-                               Mesh *origmesh = ob->data;
-                               tmpmesh->flag = origmesh->flag;
-                               tmpmesh->mat = MEM_dupallocN(origmesh->mat);
-                               tmpmesh->totcol = origmesh->totcol;
-                               tmpmesh->smoothresh = origmesh->smoothresh;
-                               if (origmesh->mat) {
-                                       for (i = origmesh->totcol; i-- > 0; ) {
-                                               /* are we an object material or data based? */
-                                               tmpmesh->mat[i] = ob->matbits[i] ? ob->mat[i] : origmesh->mat[i];
-
-                                               if (tmpmesh->mat[i]) {
-                                                       tmpmesh->mat[i]->id.us++;
-                                               }
-                                       }
-                               }
-                       }
-                       break;
-       } /* end copy materials */
-
-       if (calc_tessface) {
-               /* cycles and exporters rely on this still */
-               BKE_mesh_tessface_ensure(tmpmesh);
-       }
-
-       /* make sure materials get updated in objects */
-       test_object_materials(&tmpmesh->id);
-
-       return tmpmesh;
+       return BKE_mesh_new_from_object(bmain, sce, ob, apply_modifiers, settings, calc_tessface, calc_undeformed);
 }
 
 static void rna_Main_meshes_remove(Main *bmain, ReportList *reports, PointerRNA *mesh_ptr)
 {
        Mesh *mesh = mesh_ptr->data;
        if (ID_REAL_USERS(mesh) <= 0) {
-               BKE_libblock_free(&bmain->mesh, mesh);
+               BKE_libblock_free(bmain, mesh);
                RNA_POINTER_INVALIDATE(mesh_ptr);
        }
        else {
@@ -494,7 +336,7 @@ static void rna_Main_lamps_remove(Main *bmain, ReportList *reports, PointerRNA *
 {
        Lamp *lamp = lamp_ptr->data;
        if (ID_REAL_USERS(lamp) <= 0) {
-               BKE_libblock_free(&bmain->lamp, lamp);
+               BKE_libblock_free(bmain, lamp);
                RNA_POINTER_INVALIDATE(lamp_ptr);
        }
        else {
@@ -503,19 +345,24 @@ static void rna_Main_lamps_remove(Main *bmain, ReportList *reports, PointerRNA *
        }
 }
 
-static Image *rna_Main_images_new(Main *bmain, const char *name, int width, int height, int alpha, int float_buffer)
+static Image *rna_Main_images_new(Main *bmain, const char *name, int width, int height, int alpha, int float_buffer, int stereo3d)
 {
        float color[4] = {0.0, 0.0, 0.0, 1.0};
-       Image *image = BKE_image_add_generated(bmain, width, height, name, alpha ? 32 : 24, float_buffer, 0, color);
+       Image *image = BKE_image_add_generated(bmain, width, height, name, alpha ? 32 : 24, float_buffer, 0, color, stereo3d);
        id_us_min(&image->id);
        return image;
 }
-static Image *rna_Main_images_load(Main *bmain, ReportList *reports, const char *filepath)
+static Image *rna_Main_images_load(Main *bmain, ReportList *reports, const char *filepath, int check_existing)
 {
        Image *ima;
 
        errno = 0;
-       ima = BKE_image_load(bmain, filepath);
+       if (check_existing) {
+               ima = BKE_image_load_exists(filepath);
+       }
+       else {
+               ima = BKE_image_load(bmain, filepath);
+       }
 
        if (!ima) {
                BKE_reportf(reports, RPT_ERROR, "Cannot read '%s': %s", filepath,
@@ -528,7 +375,7 @@ static void rna_Main_images_remove(Main *bmain, ReportList *reports, PointerRNA
 {
        Image *image = image_ptr->data;
        if (ID_REAL_USERS(image) <= 0) {
-               BKE_libblock_free(&bmain->image, image);
+               BKE_libblock_free(bmain, image);
                RNA_POINTER_INVALIDATE(image_ptr);
        }
        else {
@@ -547,7 +394,7 @@ static void rna_Main_lattices_remove(Main *bmain, ReportList *reports, PointerRN
 {
        Lattice *lt = lt_ptr->data;
        if (ID_REAL_USERS(lt) <= 0) {
-               BKE_libblock_free(&bmain->latt, lt);
+               BKE_libblock_free(bmain, lt);
                RNA_POINTER_INVALIDATE(lt_ptr);
        }
        else {
@@ -566,7 +413,7 @@ static void rna_Main_curves_remove(Main *bmain, ReportList *reports, PointerRNA
 {
        Curve *cu = cu_ptr->data;
        if (ID_REAL_USERS(cu) <= 0) {
-               BKE_libblock_free(&bmain->curve, cu);
+               BKE_libblock_free(bmain, cu);
                RNA_POINTER_INVALIDATE(cu_ptr);
        }
        else {
@@ -585,7 +432,7 @@ static void rna_Main_metaballs_remove(Main *bmain, ReportList *reports, PointerR
 {
        MetaBall *mb = mb_ptr->data;
        if (ID_REAL_USERS(mb) <= 0) {
-               BKE_libblock_free(&bmain->mball, mb);
+               BKE_libblock_free(bmain, mb);
                RNA_POINTER_INVALIDATE(mb_ptr);
        }
        else {
@@ -594,12 +441,17 @@ static void rna_Main_metaballs_remove(Main *bmain, ReportList *reports, PointerR
        }
 }
 
-static VFont *rna_Main_fonts_load(Main *bmain, ReportList *reports, const char *filepath)
+static VFont *rna_Main_fonts_load(Main *bmain, ReportList *reports, const char *filepath, int check_existing)
 {
        VFont *font;
-
        errno = 0;
-       font = BKE_vfont_load(bmain, filepath);
+
+       if (check_existing) {
+               font = BKE_vfont_load_exists(bmain, filepath);
+       }
+       else {
+               font = BKE_vfont_load(bmain, filepath);
+       }
 
        if (!font)
                BKE_reportf(reports, RPT_ERROR, "Cannot read '%s': %s", filepath,
@@ -612,7 +464,7 @@ static void rna_Main_fonts_remove(Main *bmain, ReportList *reports, PointerRNA *
 {
        VFont *vfont = vfont_ptr->data;
        if (ID_REAL_USERS(vfont) <= 0) {
-               BKE_libblock_free(&bmain->vfont, vfont);
+               BKE_libblock_free(bmain, vfont);
                RNA_POINTER_INVALIDATE(vfont_ptr);
        }
        else {
@@ -623,8 +475,8 @@ static void rna_Main_fonts_remove(Main *bmain, ReportList *reports, PointerRNA *
 
 static Tex *rna_Main_textures_new(Main *bmain, const char *name, int type)
 {
-       Tex *tex = add_texture(bmain, name);
-       tex_set_type(tex, type);
+       Tex *tex = BKE_texture_add(bmain, name);
+       BKE_texture_type_set(tex, type);
        id_us_min(&tex->id);
        return tex;
 }
@@ -632,7 +484,7 @@ static void rna_Main_textures_remove(Main *bmain, ReportList *reports, PointerRN
 {
        Tex *tex = tex_ptr->data;
        if (ID_REAL_USERS(tex) <= 0) {
-               BKE_libblock_free(&bmain->tex, tex);
+               BKE_libblock_free(bmain, tex);
                RNA_POINTER_INVALIDATE(tex_ptr);
        }
        else {
@@ -641,17 +493,18 @@ static void rna_Main_textures_remove(Main *bmain, ReportList *reports, PointerRN
        }
 }
 
-static Brush *rna_Main_brushes_new(Main *bmain, const char *name)
+static Brush *rna_Main_brushes_new(Main *bmain, const char *name, int mode)
 {
-       Brush *brush = BKE_brush_add(bmain, name);
+       Brush *brush = BKE_brush_add(bmain, name, mode);
        id_us_min(&brush->id);
        return brush;
 }
+
 static void rna_Main_brushes_remove(Main *bmain, ReportList *reports, PointerRNA *brush_ptr)
 {
        Brush *brush = brush_ptr->data;
        if (ID_REAL_USERS(brush) <= 0) {
-               BKE_libblock_free(&bmain->brush, brush);
+               BKE_libblock_free(bmain, brush);
                RNA_POINTER_INVALIDATE(brush_ptr);
        }
        else {
@@ -670,7 +523,7 @@ static void rna_Main_worlds_remove(Main *bmain, ReportList *reports, PointerRNA
 {
        Group *world = world_ptr->data;
        if (ID_REAL_USERS(world) <= 0) {
-               BKE_libblock_free(&bmain->world, world);
+               BKE_libblock_free(bmain, world);
                RNA_POINTER_INVALIDATE(world_ptr);
        }
        else {
@@ -687,7 +540,7 @@ static void rna_Main_groups_remove(Main *bmain, PointerRNA *group_ptr)
 {
        Group *group = group_ptr->data;
        BKE_group_unlink(group);
-       BKE_libblock_free(&bmain->group, group);
+       BKE_libblock_free(bmain, group);
        RNA_POINTER_INVALIDATE(group_ptr);
 }
 
@@ -701,7 +554,7 @@ static void rna_Main_speakers_remove(Main *bmain, ReportList *reports, PointerRN
 {
        Speaker *speaker = speaker_ptr->data;
        if (ID_REAL_USERS(speaker) <= 0) {
-               BKE_libblock_free(&bmain->speaker, speaker);
+               BKE_libblock_free(bmain, speaker);
                RNA_POINTER_INVALIDATE(speaker_ptr);
        }
        else {
@@ -710,6 +563,33 @@ static void rna_Main_speakers_remove(Main *bmain, ReportList *reports, PointerRN
        }
 }
 
+static bSound *rna_Main_sounds_load(Main *bmain, const char *name, int check_existing)
+{
+       bSound *sound;
+
+       if (check_existing) {
+               sound = BKE_sound_new_file_exists(bmain, name);
+       }
+       else {
+               sound = BKE_sound_new_file(bmain, name);
+       }
+
+       id_us_min(&sound->id);
+       return sound;
+}
+static void rna_Main_sounds_remove(Main *bmain, ReportList *reports, PointerRNA *sound_ptr)
+{
+       Speaker *sound = sound_ptr->data;
+       if (ID_REAL_USERS(sound) <= 0) {
+               BKE_libblock_free(bmain, sound);
+               RNA_POINTER_INVALIDATE(sound_ptr);
+       }
+       else {
+               BKE_reportf(reports, RPT_ERROR, "Sound '%s' must have zero users to be removed, found %d",
+                           sound->id.name + 2, ID_REAL_USERS(sound));
+       }
+}
+
 static Text *rna_Main_texts_new(Main *bmain, const char *name)
 {
        return BKE_text_add(bmain, name);
@@ -718,16 +598,16 @@ static void rna_Main_texts_remove(Main *bmain, PointerRNA *text_ptr)
 {
        Text *text = text_ptr->data;
        BKE_text_unlink(bmain, text);
-       BKE_libblock_free(&bmain->text, text);
+       BKE_libblock_free(bmain, text);
        RNA_POINTER_INVALIDATE(text_ptr);
 }
 
-static Text *rna_Main_texts_load(Main *bmain, ReportList *reports, const char *filepath)
+static Text *rna_Main_texts_load(Main *bmain, ReportList *reports, const char *filepath, int is_internal)
 {
        Text *txt;
 
        errno = 0;
-       txt = BKE_text_load(bmain, filepath, bmain->name);
+       txt = BKE_text_load_ex(bmain, filepath, bmain->name, is_internal);
 
        if (!txt)
                BKE_reportf(reports, RPT_ERROR, "Cannot read '%s': %s", filepath,
@@ -746,7 +626,7 @@ static void rna_Main_armatures_remove(Main *bmain, ReportList *reports, PointerR
 {
        bArmature *arm = arm_ptr->data;
        if (ID_REAL_USERS(arm) <= 0) {
-               BKE_libblock_free(&bmain->armature, arm);
+               BKE_libblock_free(bmain, arm);
                RNA_POINTER_INVALIDATE(arm_ptr);
        }
        else {
@@ -766,7 +646,7 @@ static void rna_Main_actions_remove(Main *bmain, ReportList *reports, PointerRNA
 {
        bAction *act = act_ptr->data;
        if (ID_REAL_USERS(act) <= 0) {
-               BKE_libblock_free(&bmain->action, act);
+               BKE_libblock_free(bmain, act);
                RNA_POINTER_INVALIDATE(act_ptr);
        }
        else {
@@ -785,7 +665,7 @@ static void rna_Main_particles_remove(Main *bmain, ReportList *reports, PointerR
 {
        ParticleSettings *part = part_ptr->data;
        if (ID_REAL_USERS(part) <= 0) {
-               BKE_libblock_free(&bmain->particle, part);
+               BKE_libblock_free(bmain, part);
                RNA_POINTER_INVALIDATE(part_ptr);
        }
        else {
@@ -794,12 +674,37 @@ static void rna_Main_particles_remove(Main *bmain, ReportList *reports, PointerR
        }
 }
 
-static MovieClip *rna_Main_movieclip_load(Main *bmain, ReportList *reports, const char *filepath)
+static Palette *rna_Main_palettes_new(Main *bmain, const char *name)
+{
+       Palette *palette = BKE_palette_add(bmain, name);
+       id_us_min(&palette->id);
+       return (Palette *)palette;
+}
+static void rna_Main_palettes_remove(Main *bmain, ReportList *reports, PointerRNA *palette_ptr)
+{
+       Palette *palette = palette_ptr->data;
+       if (ID_REAL_USERS(palette) <= 0) {
+               BKE_libblock_free(bmain, palette);
+               RNA_POINTER_INVALIDATE(palette_ptr);
+       }
+       else {
+               BKE_reportf(reports, RPT_ERROR, "Palette settings '%s' must have zero users to be removed, found %d",
+                           palette->id.name + 2, ID_REAL_USERS(palette));
+       }
+}
+
+static MovieClip *rna_Main_movieclip_load(Main *bmain, ReportList *reports, const char *filepath, int check_existing)
 {
        MovieClip *clip;
 
        errno = 0;
-       clip = BKE_movieclip_file_add(bmain, filepath);
+
+       if (check_existing) {
+               clip = BKE_movieclip_file_add_exists(bmain, filepath);
+       }
+       else {
+               clip = BKE_movieclip_file_add(bmain, filepath);
+       }
 
        if (!clip)
                BKE_reportf(reports, RPT_ERROR, "Cannot read '%s': %s", filepath,
@@ -812,7 +717,7 @@ static void rna_Main_movieclips_remove(Main *bmain, PointerRNA *clip_ptr)
 {
        MovieClip *clip = clip_ptr->data;
        BKE_movieclip_unlink(bmain, clip);
-       BKE_libblock_free(&bmain->movieclip, clip);
+       BKE_libblock_free(bmain, clip);
        RNA_POINTER_INVALIDATE(clip_ptr);
 }
 
@@ -820,7 +725,7 @@ static Mask *rna_Main_mask_new(Main *bmain, const char *name)
 {
        Mask *mask;
 
-       mask = BKE_mask_new(bmain, "Mask");
+       mask = BKE_mask_new(bmain, name);
 
        return mask;
 }
@@ -829,7 +734,7 @@ static void rna_Main_masks_remove(Main *bmain, PointerRNA *mask_ptr)
 {
        Mask *mask = mask_ptr->data;
        BKE_mask_free(bmain, mask);
-       BKE_libblock_free(&bmain->mask, mask);
+       BKE_libblock_free(bmain, mask);
        RNA_POINTER_INVALIDATE(mask_ptr);
 }
 
@@ -838,7 +743,7 @@ static void rna_Main_grease_pencil_remove(Main *bmain, ReportList *reports, Poin
        bGPdata *gpd = gpd_ptr->data;
        if (ID_REAL_USERS(gpd) <= 0) {
                BKE_gpencil_free(gpd);
-               BKE_libblock_free(&bmain->gpencil, gpd);
+               BKE_libblock_free(bmain, gpd);
                RNA_POINTER_INVALIDATE(gpd_ptr);
        }
        else
@@ -846,17 +751,17 @@ static void rna_Main_grease_pencil_remove(Main *bmain, ReportList *reports, Poin
                            gpd->id.name + 2, ID_REAL_USERS(gpd));
 }
 
-FreestyleLineStyle *rna_Main_linestyles_new(Main *bmain, const char *name)
+static FreestyleLineStyle *rna_Main_linestyles_new(Main *bmain, const char *name)
 {
-       FreestyleLineStyle *linestyle = BKE_new_linestyle(name, bmain);
+       FreestyleLineStyle *linestyle = BKE_linestyle_new(bmain, name);
        id_us_min(&linestyle->id);
        return linestyle;
 }
 
-void rna_Main_linestyles_remove(Main *bmain, ReportList *reports, FreestyleLineStyle *linestyle)
+static void rna_Main_linestyles_remove(Main *bmain, ReportList *reports, FreestyleLineStyle *linestyle)
 {
        if (ID_REAL_USERS(linestyle) <= 0)
-               BKE_libblock_free(&bmain->linestyle, linestyle);
+               BKE_libblock_free(bmain, linestyle);
        else
                BKE_reportf(reports, RPT_ERROR, "Line style '%s' must have zero users to be removed, found %d",
                            linestyle->id.name + 2, ID_REAL_USERS(linestyle));
@@ -865,82 +770,84 @@ void rna_Main_linestyles_remove(Main *bmain, ReportList *reports, FreestyleLineS
 }
 
 /* tag functions, all the same */
-static void rna_Main_cameras_tag(Main *bmain, int value) { tag_main_lb(&bmain->camera, value); }
-static void rna_Main_scenes_tag(Main *bmain, int value) { tag_main_lb(&bmain->scene, value); }
-static void rna_Main_objects_tag(Main *bmain, int value) { tag_main_lb(&bmain->object, value); }
-static void rna_Main_materials_tag(Main *bmain, int value) { tag_main_lb(&bmain->mat, value); }
-static void rna_Main_node_groups_tag(Main *bmain, int value) { tag_main_lb(&bmain->nodetree, value); }
-static void rna_Main_meshes_tag(Main *bmain, int value) { tag_main_lb(&bmain->mesh, value); }
-static void rna_Main_lamps_tag(Main *bmain, int value) { tag_main_lb(&bmain->lamp, value); }
-static void rna_Main_libraries_tag(Main *bmain, int value) { tag_main_lb(&bmain->library, value); }
-static void rna_Main_screens_tag(Main *bmain, int value) { tag_main_lb(&bmain->screen, value); }
-static void rna_Main_window_managers_tag(Main *bmain, int value) { tag_main_lb(&bmain->wm, value); }
-static void rna_Main_images_tag(Main *bmain, int value) { tag_main_lb(&bmain->image, value); }
-static void rna_Main_lattices_tag(Main *bmain, int value) { tag_main_lb(&bmain->latt, value); }
-static void rna_Main_curves_tag(Main *bmain, int value) { tag_main_lb(&bmain->curve, value); }
-static void rna_Main_metaballs_tag(Main *bmain, int value) { tag_main_lb(&bmain->mball, value); }
-static void rna_Main_fonts_tag(Main *bmain, int value) { tag_main_lb(&bmain->vfont, value); }
-static void rna_Main_textures_tag(Main *bmain, int value) { tag_main_lb(&bmain->tex, value); }
-static void rna_Main_brushes_tag(Main *bmain, int value) { tag_main_lb(&bmain->brush, value); }
-static void rna_Main_worlds_tag(Main *bmain, int value) { tag_main_lb(&bmain->world, value); }
-static void rna_Main_groups_tag(Main *bmain, int value) { tag_main_lb(&bmain->group, value); }
-// static void rna_Main_shape_keys_tag(Main *bmain, int value) { tag_main_lb(&bmain->key, value); }
-// static void rna_Main_scripts_tag(Main *bmain, int value) { tag_main_lb(&bmain->script, value); }
-static void rna_Main_texts_tag(Main *bmain, int value) { tag_main_lb(&bmain->text, value); }
-static void rna_Main_speakers_tag(Main *bmain, int value) { tag_main_lb(&bmain->speaker, value); }
-static void rna_Main_sounds_tag(Main *bmain, int value) { tag_main_lb(&bmain->sound, value); }
-static void rna_Main_armatures_tag(Main *bmain, int value) { tag_main_lb(&bmain->armature, value); }
-static void rna_Main_actions_tag(Main *bmain, int value) { tag_main_lb(&bmain->action, value); }
-static void rna_Main_particles_tag(Main *bmain, int value) { tag_main_lb(&bmain->particle, value); }
-static void rna_Main_gpencil_tag(Main *bmain, int value) { tag_main_lb(&bmain->gpencil, value); }
-static void rna_Main_movieclips_tag(Main *bmain, int value) { tag_main_lb(&bmain->movieclip, value); }
-static void rna_Main_masks_tag(Main *bmain, int value) { tag_main_lb(&bmain->mask, value); }
-static void rna_Main_linestyle_tag(Main *bmain, int value) { tag_main_lb(&bmain->linestyle, value); }
-
-static int rna_Main_cameras_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_CA); }
-static int rna_Main_scenes_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_SCE); }
-static int rna_Main_objects_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_OB); }
-static int rna_Main_materials_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_MA); }
-static int rna_Main_node_groups_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_NT); }
-static int rna_Main_meshes_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_ME); }
-static int rna_Main_lamps_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_LA); }
-static int rna_Main_libraries_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_LI); }
-static int rna_Main_screens_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_SCR); }
-static int rna_Main_window_managers_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_WM); }
-static int rna_Main_images_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_IM); }
-static int rna_Main_lattices_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_LT); }
-static int rna_Main_curves_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_CU); }
-static int rna_Main_metaballs_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_MB); }
-static int rna_Main_fonts_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_VF); }
-static int rna_Main_textures_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_TE); }
-static int rna_Main_brushes_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_BR); }
-static int rna_Main_worlds_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_WO); }
-static int rna_Main_groups_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_GR); }
-static int rna_Main_texts_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_TXT); }
-static int rna_Main_speakers_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_SPK); }
-static int rna_Main_sounds_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_SO); }
-static int rna_Main_armatures_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_AR); }
-static int rna_Main_actions_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_AC); }
-static int rna_Main_particles_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_PA); }
-static int rna_Main_gpencil_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_GD); }
+static void rna_Main_cameras_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->camera, value); }
+static void rna_Main_scenes_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->scene, value); }
+static void rna_Main_objects_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->object, value); }
+static void rna_Main_materials_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->mat, value); }
+static void rna_Main_node_groups_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->nodetree, value); }
+static void rna_Main_meshes_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->mesh, value); }
+static void rna_Main_lamps_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->lamp, value); }
+static void rna_Main_libraries_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->library, value); }
+static void rna_Main_screens_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->screen, value); }
+static void rna_Main_window_managers_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->wm, value); }
+static void rna_Main_images_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->image, value); }
+static void rna_Main_lattices_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->latt, value); }
+static void rna_Main_curves_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->curve, value); }
+static void rna_Main_metaballs_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->mball, value); }
+static void rna_Main_fonts_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->vfont, value); }
+static void rna_Main_textures_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->tex, value); }
+static void rna_Main_brushes_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->brush, value); }
+static void rna_Main_worlds_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->world, value); }
+static void rna_Main_groups_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->group, value); }
+// static void rna_Main_shape_keys_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->key, value); }
+// static void rna_Main_scripts_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->script, value); }
+static void rna_Main_texts_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->text, value); }
+static void rna_Main_speakers_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->speaker, value); }
+static void rna_Main_sounds_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->sound, value); }
+static void rna_Main_armatures_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->armature, value); }
+static void rna_Main_actions_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->action, value); }
+static void rna_Main_particles_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->particle, value); }
+static void rna_Main_palettes_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->palettes, value); }
+static void rna_Main_gpencil_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->gpencil, value); }
+static void rna_Main_movieclips_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->movieclip, value); }
+static void rna_Main_masks_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->mask, value); }
+static void rna_Main_linestyle_tag(Main *bmain, int value) { BKE_main_id_tag_listbase(&bmain->linestyle, value); }
+
+static int rna_Main_cameras_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_CA) != 0; }
+static int rna_Main_scenes_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_SCE) != 0; }
+static int rna_Main_objects_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_OB) != 0; }
+static int rna_Main_materials_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_MA) != 0; }
+static int rna_Main_node_groups_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_NT) != 0; }
+static int rna_Main_meshes_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_ME) != 0; }
+static int rna_Main_lamps_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_LA) != 0; }
+static int rna_Main_libraries_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_LI) != 0; }
+static int rna_Main_screens_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_SCR) != 0; }
+static int rna_Main_window_managers_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_WM) != 0; }
+static int rna_Main_images_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_IM) != 0; }
+static int rna_Main_lattices_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_LT) != 0; }
+static int rna_Main_curves_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_CU) != 0; }
+static int rna_Main_metaballs_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_MB) != 0; }
+static int rna_Main_fonts_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_VF) != 0; }
+static int rna_Main_textures_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_TE) != 0; }
+static int rna_Main_brushes_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_BR) != 0; }
+static int rna_Main_worlds_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_WO) != 0; }
+static int rna_Main_groups_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_GR) != 0; }
+static int rna_Main_texts_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_TXT) != 0; }
+static int rna_Main_speakers_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_SPK) != 0; }
+static int rna_Main_sounds_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_SO) != 0; }
+static int rna_Main_armatures_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_AR) != 0; }
+static int rna_Main_actions_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_AC) != 0; }
+static int rna_Main_particles_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_PA) != 0; }
+static int rna_Main_palettes_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_PAL) != 0; }
+static int rna_Main_gpencil_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_GD) != 0; }
+static int rna_Main_linestyle_is_updated_get(PointerRNA *ptr) { return DAG_id_type_tagged(ptr->data, ID_LS) != 0; }
 
 #else
 
-void RNA_api_main(StructRNA *srna)
+void RNA_api_main(StructRNA *UNUSED(srna))
 {
 #if 0
        FunctionRNA *func;
        PropertyRNA *parm;
+
        /* maybe we want to add functions in 'bpy.data' still?
         * for now they are all in collections bpy.data.images.new(...) */
        func = RNA_def_function(srna, "add_image", "rna_Main_add_image");
        RNA_def_function_ui_description(func, "Add a new image");
-       parm = RNA_def_string_file_path(func, "filepath", "", 0, "", "File path to load image from");
+       parm = RNA_def_string_file_path(func, "filepath", NULL, 0, "", "File path to load image from");
        RNA_def_property_flag(parm, PROP_REQUIRED);
        parm = RNA_def_pointer(func, "image", "Image", "", "New image");
        RNA_def_function_return(func, parm);
-#else
-       (void)srna;
 #endif
 }
 
@@ -1172,6 +1079,7 @@ void RNA_def_main_meshes(BlenderRNA *brna, PropertyRNA *cprop)
        parm = RNA_def_enum(func, "settings", mesh_type_items, 0, "", "Modifier settings to apply");
        RNA_def_property_flag(parm, PROP_REQUIRED);
        RNA_def_boolean(func, "calc_tessface", true, "Calculate Tessellation", "Calculate tessellation faces");
+       RNA_def_boolean(func, "calc_undeformed", false, "Calculate Undeformed", "Calculate undeformed vertex coordinates");
        parm = RNA_def_pointer(func, "mesh", "Mesh", "",
                               "Mesh created from object, remove it if it is only used for export");
        RNA_def_function_return(func, parm);
@@ -1313,6 +1221,7 @@ void RNA_def_main_images(BlenderRNA *brna, PropertyRNA *cprop)
        RNA_def_property_flag(parm, PROP_REQUIRED);
        RNA_def_boolean(func, "alpha", 0, "Alpha", "Use alpha channel");
        RNA_def_boolean(func, "float_buffer", 0, "Float Buffer", "Create an image with floating point color");
+       RNA_def_boolean(func, "stereo3d", 0, "Stereo 3D", "Create left and right views");
        /* return type */
        parm = RNA_def_pointer(func, "image", "Image", "", "New image datablock");
        RNA_def_function_return(func, parm);
@@ -1322,6 +1231,7 @@ void RNA_def_main_images(BlenderRNA *brna, PropertyRNA *cprop)
        RNA_def_function_ui_description(func, "Load a new image into the main database");
        parm = RNA_def_string_file_path(func, "filepath", "File Path", 0, "", "path of the file to load");
        RNA_def_property_flag(parm, PROP_REQUIRED);
+       RNA_def_boolean(func, "check_existing", false, "", "Using existing data-block if this file is already loaded");
        /* return type */
        parm = RNA_def_pointer(func, "image", "Image", "", "New image datablock");
        RNA_def_function_return(func, parm);
@@ -1466,6 +1376,7 @@ void RNA_def_main_fonts(BlenderRNA *brna, PropertyRNA *cprop)
        RNA_def_function_ui_description(func, "Load a new font into the main database");
        parm = RNA_def_string_file_path(func, "filepath", "File Path", 0, "", "path of the font to load");
        RNA_def_property_flag(parm, PROP_REQUIRED);
+       RNA_def_boolean(func, "check_existing", false, "", "Using existing data-block if this file is already loaded");
        /* return type */
        parm = RNA_def_pointer(func, "vfont", "VectorFont", "", "New font datablock");
        RNA_def_function_return(func, parm);
@@ -1538,6 +1449,7 @@ void RNA_def_main_brushes(BlenderRNA *brna, PropertyRNA *cprop)
        RNA_def_function_ui_description(func, "Add a new brush to the main database");
        parm = RNA_def_string(func, "name", "Brush", 0, "", "New name for the datablock");
        RNA_def_property_flag(parm, PROP_REQUIRED);
+       parm = RNA_def_enum(func, "mode", object_mode_items, OB_MODE_TEXTURE_PAINT, "", "Paint Mode for the new brush");
        /* return type */
        parm = RNA_def_pointer(func, "brush", "Brush", "", "New brush datablock");
        RNA_def_function_return(func, parm);
@@ -1697,6 +1609,7 @@ void RNA_def_main_texts(BlenderRNA *brna, PropertyRNA *cprop)
        RNA_def_function_ui_description(func, "Add a new text to the main database from a file");
        parm = RNA_def_string_file_path(func, "filepath", "Path", FILE_MAX, "", "path for the datablock");
        RNA_def_property_flag(parm, PROP_REQUIRED);
+       parm = RNA_def_boolean(func, "internal", 0, "Make internal", "Make text file internal after loading");
        /* return type */
        parm = RNA_def_pointer(func, "text", "Text", "", "New text datablock");
        RNA_def_function_return(func, parm);
@@ -1722,7 +1635,22 @@ void RNA_def_main_sounds(BlenderRNA *brna, PropertyRNA *cprop)
        RNA_def_struct_sdna(srna, "Main");
        RNA_def_struct_ui_text(srna, "Main Sounds", "Collection of sounds");
 
-       /* TODO, 'load' */
+       /* load func */
+       func = RNA_def_function(srna, "load", "rna_Main_sounds_load");
+       RNA_def_function_ui_description(func, "Add a new sound to the main database from a file");
+       parm = RNA_def_string_file_path(func, "filepath", "Path", FILE_MAX, "", "path for the datablock");
+       RNA_def_property_flag(parm, PROP_REQUIRED);
+       RNA_def_boolean(func, "check_existing", false, "", "Using existing data-block if this file is already loaded");
+       /* return type */
+       parm = RNA_def_pointer(func, "sound", "Sound", "", "New text datablock");
+       RNA_def_function_return(func, parm);
+
+       func = RNA_def_function(srna, "remove", "rna_Main_sounds_remove");
+       RNA_def_function_flag(func, FUNC_USE_REPORTS);
+       RNA_def_function_ui_description(func, "Remove a sound from the current blendfile");
+       parm = RNA_def_pointer(func, "sound", "Sound", "", "Sound to remove");
+       RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR);
+       RNA_def_property_clear_flag(parm, PROP_THICK_WRAP);
 
        func = RNA_def_function(srna, "tag", "rna_Main_sounds_tag");
        parm = RNA_def_boolean(func, "value", 0, "Value", "");
@@ -1838,7 +1766,41 @@ void RNA_def_main_particles(BlenderRNA *brna, PropertyRNA *cprop)
        RNA_def_property_clear_flag(prop, PROP_EDITABLE);
        RNA_def_property_boolean_funcs(prop, "rna_Main_particles_is_updated_get", NULL);
 }
+void RNA_def_main_palettes(BlenderRNA *brna, PropertyRNA *cprop)
+{
+       StructRNA *srna;
+       FunctionRNA *func;
+       PropertyRNA *parm;
+       PropertyRNA *prop;
+
+       RNA_def_property_srna(cprop, "BlendDataPalettes");
+       srna = RNA_def_struct(brna, "BlendDataPalettes", NULL);
+       RNA_def_struct_sdna(srna, "Main");
+       RNA_def_struct_ui_text(srna, "Main Palettes", "Collection of palettes");
+
+       func = RNA_def_function(srna, "new", "rna_Main_palettes_new");
+       RNA_def_function_ui_description(func, "Add a new palette to the main database");
+       parm = RNA_def_string(func, "name", "Palette", 0, "", "New name for the datablock");
+       RNA_def_property_flag(parm, PROP_REQUIRED);
+       /* return type */
+       parm = RNA_def_pointer(func, "palette", "Palette", "", "New palette datablock");
+       RNA_def_function_return(func, parm);
 
+       func = RNA_def_function(srna, "remove", "rna_Main_palettes_remove");
+       RNA_def_function_flag(func, FUNC_USE_REPORTS);
+       RNA_def_function_ui_description(func, "Remove a palette from the current blendfile");
+       parm = RNA_def_pointer(func, "palette", "Palette", "", "Palette to remove");
+       RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR);
+       RNA_def_property_clear_flag(parm, PROP_THICK_WRAP);
+
+       func = RNA_def_function(srna, "tag", "rna_Main_palettes_tag");
+       parm = RNA_def_boolean(func, "value", 0, "Value", "");
+       RNA_def_property_flag(parm, PROP_REQUIRED);
+
+       prop = RNA_def_property(srna, "is_updated", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_boolean_funcs(prop, "rna_Main_palettes_is_updated_get", NULL);
+}
 void RNA_def_main_gpencil(BlenderRNA *brna, PropertyRNA *cprop)
 {
        StructRNA *srna;
@@ -1902,6 +1864,7 @@ void RNA_def_main_movieclips(BlenderRNA *brna, PropertyRNA *cprop)
        RNA_def_function_ui_description(func, "Add a new movie clip to the main database from a file");
        parm = RNA_def_string_file_path(func, "filepath", "Path", FILE_MAX, "", "path for the datablock");
        RNA_def_property_flag(parm, PROP_REQUIRED);
+       RNA_def_boolean(func, "check_existing", false, "", "Using existing data-block if this file is already loaded");
        /* return type */
        parm = RNA_def_pointer(func, "clip", "MovieClip", "", "New movie clip datablock");
        RNA_def_function_return(func, parm);
@@ -1925,7 +1888,7 @@ void RNA_def_main_masks(BlenderRNA *brna, PropertyRNA *cprop)
        /* new func */
        func = RNA_def_function(srna, "new", "rna_Main_mask_new");
        RNA_def_function_ui_description(func, "Add a new mask with a given name to the main database");
-       RNA_def_string_file_path(func, "name", "", MAX_ID_NAME - 2, "Mask", "Name of new mask datablock");
+       RNA_def_string_file_path(func, "name", NULL, MAX_ID_NAME - 2, "Mask", "Name of new mask datablock");
        /* return type */
        parm = RNA_def_pointer(func, "mask", "Mask", "", "New mask datablock");
        RNA_def_function_return(func, parm);
@@ -1943,12 +1906,17 @@ void RNA_def_main_linestyles(BlenderRNA *brna, PropertyRNA *cprop)
        StructRNA *srna;
        FunctionRNA *func;
        PropertyRNA *parm;
+       PropertyRNA *prop;
 
        RNA_def_property_srna(cprop, "BlendDataLineStyles");
        srna = RNA_def_struct(brna, "BlendDataLineStyles", NULL);
        RNA_def_struct_sdna(srna, "Main");
        RNA_def_struct_ui_text(srna, "Main Line Styles", "Collection of line styles");
 
+       func = RNA_def_function(srna, "tag", "rna_Main_linestyle_tag");
+       parm = RNA_def_boolean(func, "value", 0, "Value", "");
+       RNA_def_property_flag(parm, PROP_REQUIRED);
+
        func = RNA_def_function(srna, "new", "rna_Main_linestyles_new");
        RNA_def_function_ui_description(func, "Add a new line style instance to the main database");
        parm = RNA_def_string(func, "name", "FreestyleLineStyle", 0, "", "New name for the datablock");
@@ -1962,6 +1930,10 @@ void RNA_def_main_linestyles(BlenderRNA *brna, PropertyRNA *cprop)
        RNA_def_function_ui_description(func, "Remove a line style instance from the current blendfile");
        parm = RNA_def_pointer(func, "linestyle", "FreestyleLineStyle", "", "Line style to remove");
        RNA_def_property_flag(parm, PROP_REQUIRED);
+
+       prop = RNA_def_property(srna, "is_updated", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_boolean_funcs(prop, "rna_Main_linestyle_is_updated_get", NULL);
 }
 
 #endif