4d5d5962c6339fad3edf8027bb8e72e98ace3606
[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 <BKE_global.h>
35 #include <BKE_main.h>
36 #include <DNA_ID.h>
37 #include <DNA_camera_types.h>
38 #include <DNA_lamp_types.h>
39 #include <DNA_material_types.h>
40 #include <DNA_object_types.h>
41 #include <DNA_scene_types.h>
42 #include <DNA_world_types.h>
43
44 #include "datablock.h"
45 #include "gen_utils.h"
46 #include "modules.h"
47
48 void initBlenderApi2_2x (void)
49 {
50         printf ("initBlenderApi2_2x\n");
51         initBlender ();
52 }
53
54 void setScriptLinks(ID *id, short event)
55 {
56         PyObject *link;
57         int       obj_id;
58
59         printf ("In setScriptLinks (id=?, event=%d)\n", event);
60         if (!g_blenderdict)
61         {
62                 /* Not initialized yet. This can happen at first file load. */
63                 return;
64         }
65
66         obj_id = MAKE_ID2 (id->name[0], id->name[1]);
67         if (obj_id == ID_SCE)
68         {
69                 Py_INCREF(Py_None);
70                 link = Py_None;
71         }
72         else
73         {
74                 link = Py_None;
75                 switch (obj_id)
76                 {
77                         case ID_OB:
78                                 /* Create a new datablock of type: Object */
79                                 /*
80                                 link = ObjectCreatePyObject (G.main->object);
81                                 */
82                                 break;
83                         case ID_ME:
84                                 /* Create a new datablock of type: Mesh */
85                                 break;
86                         case ID_LA:
87                                 /* Create a new datablock of type: Lamp */
88                                 break;
89                         case ID_CA:
90                                 /* Create a new datablock of type: Camera */
91                                 break;
92                         case ID_MA:
93                                 /* Create a new datablock of type: Material */
94                                 break;
95                         case ID_WO:
96                                 /* Create a new datablock of type: World */
97                                 break;
98                         case ID_IP:
99                                 /* Create a new datablock of type: Ipo */
100                                 break;
101                         case ID_IM:
102                                 /* Create a new datablock of type: Image */
103                                 break;
104                         case ID_TXT:
105                                 /* Create a new datablock of type: Text */
106                                 break;
107                         default:
108                                 PythonReturnErrorObject (PyExc_SystemError,
109                                                         "Unable to create block for data");
110                                 return;
111                 }
112                 /* link = DataBlockFromID(id); */
113         }
114
115         if (!link)
116         {
117                 printf ("Internal error, unable to create PyBlock for script link\n");
118                 printf ("This is a bug; please report to bugs@blender.nl");
119                 Py_INCREF(Py_False);
120                 PyDict_SetItemString(g_blenderdict, "bylink", Py_False);
121                 return;
122         } else {
123                 Py_INCREF(Py_True);
124                 PyDict_SetItemString(g_blenderdict, "bylink", Py_True);
125         }
126
127         PyDict_SetItemString(g_blenderdict, "link", link);
128         PyDict_SetItemString(g_blenderdict, "event",
129                         Py_BuildValue("s", event_to_name(event)));
130 }