Revision: 36870
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36870
Author:   psy-fi
Date:     2011-05-24 15:44:13 +0000 (Tue, 24 May 2011)
Log Message:
-----------
merge to trunk with svn merge ^/trunk/blender after warning on irc to avoid 
possible svn corruption

Modified Paths:
--------------
    
branches/soc-2011-onion/doc/python_api/examples/bpy.types.BlendDataLibraries.load.py
    branches/soc-2011-onion/source/blender/blenloader/BLO_readfile.h
    branches/soc-2011-onion/source/blender/blenloader/intern/readfile.c
    branches/soc-2011-onion/source/blender/python/intern/bpy_library.c

Property Changed:
----------------
    branches/soc-2011-onion/


Property changes on: branches/soc-2011-onion
___________________________________________________________________
Modified: svn:mergeinfo
   - /trunk/blender:36834-36865
   + /trunk/blender:36833-36869

Modified: 
branches/soc-2011-onion/doc/python_api/examples/bpy.types.BlendDataLibraries.load.py
===================================================================
--- 
branches/soc-2011-onion/doc/python_api/examples/bpy.types.BlendDataLibraries.load.py
        2011-05-24 15:21:14 UTC (rev 36869)
+++ 
branches/soc-2011-onion/doc/python_api/examples/bpy.types.BlendDataLibraries.load.py
        2011-05-24 15:44:13 UTC (rev 36870)
@@ -21,3 +21,19 @@
 with bpy.data.libraries.load(filepath) as (data_from, data_to):
     for attr in dir(data_to):
         setattr(data_to, attr, getattr(data_from, attr))
+
+
+# the 'data_to' variables lists are 
+with bpy.data.libraries.load(filepath) as (data_from, data_to):
+    data_to.scenes = ["Scene"]
+
+
+# the loaded objects can be accessed from 'data_to' outside of the context
+# since loading the data replaces the strings for the datablocks or None
+# if the datablock could not be loaded.
+with bpy.data.libraries.load(filepath) as (data_from, data_to):
+    data_to.meshes = data_from.meshes
+# now operate directly on the loaded data
+for mesh in mdata_to.meshes:
+    if mesh is not None:
+        print(mesh.name)

Modified: branches/soc-2011-onion/source/blender/blenloader/BLO_readfile.h
===================================================================
--- branches/soc-2011-onion/source/blender/blenloader/BLO_readfile.h    
2011-05-24 15:21:14 UTC (rev 36869)
+++ branches/soc-2011-onion/source/blender/blenloader/BLO_readfile.h    
2011-05-24 15:44:13 UTC (rev 36870)
@@ -224,7 +224,7 @@
  * @param flag Options for linking, used for instancing.
  * @return Boolean, 0 when the datablock could not be found.
  */
-int BLO_library_append_named_part(const struct bContext *C, struct Main 
*mainl, BlendHandle** bh, const char *idname, int idcode, short flag);
+struct ID *BLO_library_append_named_part(const struct bContext *C, struct Main 
*mainl, BlendHandle** bh, const char *idname, int idcode, short flag);
 void BLO_library_append_end(const struct bContext *C, struct Main *mainl, 
BlendHandle** bh, int idcode, short flag);
 
 void *BLO_library_read_struct(struct FileData *fd, struct BHead *bh, const 
char *blockname);

Modified: branches/soc-2011-onion/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/soc-2011-onion/source/blender/blenloader/intern/readfile.c 
2011-05-24 15:21:14 UTC (rev 36869)
+++ branches/soc-2011-onion/source/blender/blenloader/intern/readfile.c 
2011-05-24 15:44:13 UTC (rev 36870)
@@ -12804,13 +12804,13 @@
 
 /* returns true if the item was found
  * but it may already have already been appended/linked */
-static int append_named_part(const bContext *C, Main *mainl, FileData *fd, 
const char *idname, int idcode, short flag)
+static ID *append_named_part(const bContext *C, Main *mainl, FileData *fd, 
const char *idname, int idcode, short flag)
 {
-       Scene *scene= CTX_data_scene(C);
+       Scene *scene= CTX_data_scene(C); /* can be NULL */
        Object *ob;
        Base *base;
        BHead *bhead;
-       ID *id;
+       ID *id= NULL;
        int endloop=0;
        int found=0;
 
@@ -12825,7 +12825,7 @@
                                found= 1;
                                id= is_yet_read(fd, mainl, bhead);
                                if(id==NULL) {
-                                       read_libblock(fd, mainl, bhead, 
LIB_TESTEXT, NULL);
+                                       read_libblock(fd, mainl, bhead, 
LIB_TESTEXT, &id);
                                }
                                else {
                                        printf("append: already linked\n");
@@ -12836,13 +12836,13 @@
                                        }
                                }
 
-                               if(idcode==ID_OB && scene) {    /* loose 
object: give a base */
+                               /* TODO, move out of append and into own func 
the caller can use */
+                               if(scene && id && (GS(id->name) == ID_OB)) {    
/* loose object: give a base */
                                        base= MEM_callocN( sizeof(Base), 
"app_nam_part");
                                        BLI_addtail(&scene->base, base);
 
-                                       if(id==NULL) ob= mainl->object.last;
-                                       else ob= (Object *)id;
-                                       
+                                       ob= (Object *)id;
+
                                        /* link at active layer (view3d->lay if 
in context, else scene->lay */
                                        if((flag & FILE_ACTIVELAY)) {
                                                View3D *v3d = CTX_wm_view3d(C);
@@ -12870,10 +12870,13 @@
                bhead = blo_nextbhead(fd, bhead);
        }
 
-       return found;
+       /* if we found the id but the id is NULL, this is really bad */
+       BLI_assert((found != 0) == (id != NULL));
+
+       return found ? id : NULL;
 }
 
-int BLO_library_append_named_part(const bContext *C, Main *mainl, 
BlendHandle** bh, const char *idname, int idcode, short flag)
+ID *BLO_library_append_named_part(const bContext *C, Main *mainl, 
BlendHandle** bh, const char *idname, int idcode, short flag)
 {
        FileData *fd= (FileData*)(*bh);
        return append_named_part(C, mainl, fd, idname, idcode, flag);

Modified: branches/soc-2011-onion/source/blender/python/intern/bpy_library.c
===================================================================
--- branches/soc-2011-onion/source/blender/python/intern/bpy_library.c  
2011-05-24 15:21:14 UTC (rev 36869)
+++ branches/soc-2011-onion/source/blender/python/intern/bpy_library.c  
2011-05-24 15:44:13 UTC (rev 36870)
@@ -26,6 +26,9 @@
  *  \ingroup pythonintern
  */
 
+/* nifty feature. swap out strings for RNA data */
+#define USE_RNA_DATABLOCKS
+
 #include <Python.h>
 #include <stddef.h>
 
@@ -47,6 +50,11 @@
 
 #include "bpy_util.h"
 
+#ifdef USE_RNA_DATABLOCKS
+#  include "bpy_rna.h"
+#  include "RNA_access.h"
+#endif
+
 typedef struct {
        PyObject_HEAD /* required python macro   */
        /* collection iterator spesific parts */
@@ -271,6 +279,36 @@
        return ret;
 }
 
+static void bpy_lib_exit_warn_idname(BPy_Library *self, const char 
*name_plural, const char *idname)
+{
+       PyObject *exc, *val, *tb;
+       PyErr_Fetch(&exc, &val, &tb);
+       if (PyErr_WarnFormat(PyExc_UserWarning, 1,
+                                                "load: '%s' does not contain 
%s[\"%s\"]",
+                            self->abspath, name_plural, idname)) {
+               /* Spurious errors can appear at shutdown */
+               if (PyErr_ExceptionMatches(PyExc_Warning)) {
+                       PyErr_WriteUnraisable((PyObject *)self);
+               }
+       }
+       PyErr_Restore(exc, val, tb);
+}
+
+static void bpy_lib_exit_warn_type(BPy_Library *self, PyObject *item)
+{
+       PyObject *exc, *val, *tb;
+       PyErr_Fetch(&exc, &val, &tb);
+       if (PyErr_WarnFormat(PyExc_UserWarning, 1,
+                                                "load: '%s' expected a string 
type, not a %.200s",
+                            self->abspath, Py_TYPE(item)->tp_name)) {
+               /* Spurious errors can appear at shutdown */
+               if (PyErr_ExceptionMatches(PyExc_Warning)) {
+                       PyErr_WriteUnraisable((PyObject *)self);
+               }
+       }
+       PyErr_Restore(exc, val, tb);
+}
+
 static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
 {
        Main *mainl= NULL;
@@ -302,18 +340,41 @@
                                                // printf("  %s\n", item_str);
 
                                                if(item_str) {
-                                                       
if(!BLO_library_append_named_part(NULL, mainl, &(self->blo_handle), item_str, 
code, self->flag)) {
-                                                               
PyErr_Format(PyExc_KeyError,
-                                                                            
"load: %s does not contain %s[\"%s\"]",
-                                                                            
self->abspath, name_plural, item_str);
-                                                               err= -1;
-                                                               break;
+                                                       ID *id= 
BLO_library_append_named_part(NULL, mainl, &(self->blo_handle), item_str, code, 
self->flag);
+                                                       if(id) {
+#ifdef USE_RNA_DATABLOCKS
+                                                               PointerRNA 
id_ptr;
+                                                               
RNA_id_pointer_create(id, &id_ptr);
+                                                               Py_DECREF(item);
+                                                               item= 
pyrna_struct_CreatePyObject(&id_ptr);
+#endif
                                                        }
+                                                       else {
+                                                               
bpy_lib_exit_warn_idname(self, name_plural, item_str);
+                                                               /* just warn 
for now */
+                                                               /* err = -1; */
+#ifdef USE_RNA_DATABLOCKS
+                                                               item= Py_None;
+                                                               Py_INCREF(item);
+#endif
+                                                       }
+
+                                                       /* ID or None */
                                                }
                                                else {
                                                        /* XXX, could complain 
about this */
+                                                       
bpy_lib_exit_warn_type(self, item);
                                                        PyErr_Clear();
+
+#ifdef USE_RNA_DATABLOCKS
+                                                       item= Py_None;
+                                                       Py_INCREF(item);
+#endif
                                                }
+
+#ifdef USE_RNA_DATABLOCKS
+                                               PyList_SET_ITEM(ls, i, item);
+#endif
                                        }
                                }
                        }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to