[Bf-committers] (Fix) for bug 1212 Changing object's layer doesnt work

Kenneth Styrberg bf-committers@blender.org
Wed, 19 May 2004 22:05:46 +0200


Hi, heres a solution to bug 1212.

It's not a bug fix but a new function that takes care of moving objects 
between layers.

I cloned function movetolayer() and reshaped it.

If all this is crap, then waste it. Anyways it's been a good tutor to 
wade through all code...


regards

//styken




Index: editobject.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/editobject.c,v
retrieving revision 1.85
diff -u -r1.85 editobject.c
--- editobject.c    24 Apr 2004 21:09:06 -0000    1.85
+++ editobject.c    19 May 2004 20:02:04 -0000
@@ -1470,6 +1470,46 @@
     allqueue(REDRAWINFO, 0);
 }
 
+void changelayer(struct Object * object)
+{
+    
+    Base *base;
+    unsigned int lay = 0, local;
+
+    lay = object->lay;
+
+    /* Do some sanity check */
+    if (lay > 20)
+        lay = 2 << 18;
+    else if (lay < 2)
+        lay = 1;
+    else
+        lay = 2 << (lay - 2);
+
+    /* The bit shift, 2 <<, is for the layers are bit wise selected. 1, 
2, 4, 8, ... */
+
+    lay &= 0xFFFFFF;
+    
+    if(lay==0)
+        return;
+
+    base= FIRSTBASE;
+    while(base) {
+        if (base->object == object) {
+            local= base->lay & 0xFF000000;
+            base->lay= lay + local;
+
+            base->object->lay= lay;
+        }
+        base= base->next;
+    }
+
+    countall();
+    allqueue(REDRAWBUTSEDIT, 0);
+    allqueue(REDRAWVIEW3D, 0);
+    allqueue(REDRAWOOPS, 0);
+    allqueue(REDRAWINFO, 0);
+}
 
 void special_editmenu(void)
 {

***** CVS exited normally with code 1 *****


Index: Object.c
===================================================================
RCS file: 
/cvsroot/bf-blender/blender/source/blender/python/api2_2x/Object.c,v
retrieving revision 1.69
diff -u -r1.69 Object.c
--- Object.c    12 May 2004 08:06:15 -0000    1.69
+++ Object.c    19 May 2004 20:02:45 -0000
@@ -1622,6 +1622,7 @@
     struct Ika        * ika;
 
     object = obj->object;
+
     if (StringEqual (name, "LocX"))
         return (PyFloat_FromDouble(object->loc[0]));
     if (StringEqual (name, "LocY"))
@@ -1849,8 +1850,14 @@
         }
         return (0);
     }
-    if (StringEqual (name, "Layer"))
-        return (!PyArg_Parse (value, "i", &(object->lay)));
+    if (StringEqual (name, "Layer")) {
+
+        int retTemp = 0;
+        retTemp = !PyArg_Parse (value, "i", &(object->lay));
+        changelayer(object);
+        return retTemp;
+    }
+
     if (StringEqual (name, "parent"))
     {
         /* This is not allowed. */

***** CVS exited normally with code 1 *****