* Moved the code to retrieve an object by name to a seperate function in
[blender.git] / source / blender / python / api2_2x / interface.c
1 /* 
2  *
3  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version. The Blender
9  * Foundation also sells licenses for use in proprietary software under
10  * the Blender License.  See http://www.blender.org/BL/ for information
11  * about this.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  *
22  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23  * All rights reserved.
24  *
25  * This is a new part of Blender.
26  *
27  * Contributor(s): Michel Selten
28  *
29  * ***** END GPL/BL DUAL LICENSE BLOCK *****
30 */
31
32 #include <stdio.h>
33
34 #include <Python.h>
35
36 #include <BKE_global.h>
37 #include <BKE_main.h>
38 #include <DNA_ID.h>
39 #include <DNA_camera_types.h>
40 #include <DNA_lamp_types.h>
41 #include <DNA_material_types.h>
42 #include <DNA_object_types.h>
43 #include <DNA_scene_types.h>
44 #include <DNA_scriptlink_types.h>
45 #include <DNA_world_types.h>
46
47 #include "gen_utils.h"
48 #include "modules.h"
49
50 void initBlenderApi2_2x (void)
51 {
52         printf ("initBlenderApi2_2x\n");
53         g_blenderdict = NULL;
54         initBlender ();
55 }
56
57 ScriptLink * setScriptLinks(ID *id, short event)
58 {
59         ScriptLink  * scriptlink;
60         PyObject    * link;
61         Object      * object;
62         int           obj_id;
63
64         obj_id = MAKE_ID2 (id->name[0], id->name[1]);
65         printf ("In setScriptLinks (id=%s, event=%d)\n",id->name, event);
66
67         switch (obj_id)
68         {
69                 case ID_OB:
70                         object = GetObjectByName (GetIdName (id));
71                         if (object == NULL)
72                         {
73                                 return NULL;
74                         }
75                         link = ObjectCreatePyObject (object);
76                         scriptlink = &(object->scriptlink);
77                         break;
78                 case ID_LA:
79                         scriptlink = NULL;
80                         Py_INCREF(Py_None);
81                         link = Py_None;
82                         break;
83                 case ID_CA:
84                         scriptlink = NULL;
85                         Py_INCREF(Py_None);
86                         link = Py_None;
87                         break;
88                 case ID_MA:
89                         scriptlink = NULL;
90                         Py_INCREF(Py_None);
91                         link = Py_None;
92                         break;
93                 case ID_WO:
94                         scriptlink = NULL;
95                         Py_INCREF(Py_None);
96                         link = Py_None;
97                         break;
98                 case ID_SCE:
99                         scriptlink = NULL;
100                         Py_INCREF(Py_None);
101                         link = Py_None;
102                         break;
103                 default:
104                         Py_INCREF(Py_None);
105                         link = Py_None;
106                         return NULL;
107         }
108
109         if (scriptlink == NULL)
110         {
111                 /* This is probably not an internal error anymore :)
112 TODO: Check this
113                 printf ("Internal error, unable to create PyBlock for script link\n");
114                 */
115                 Py_INCREF(Py_False);
116                 PyDict_SetItemString(g_blenderdict, "bylink", Py_False);
117                 return NULL;
118         }
119         else
120         {
121                 Py_INCREF(Py_True);
122                 PyDict_SetItemString(g_blenderdict, "bylink", Py_True);
123         }
124
125         PyDict_SetItemString(g_blenderdict, "link", link);
126         PyDict_SetItemString(g_blenderdict, "event",
127                         Py_BuildValue("s", event_to_name(event)));
128
129         return (scriptlink);
130 }