|
Blender
V2.59
|
00001 /* 00002 * $Id: idcode.c 35493 2011-03-12 14:38:00Z campbellbarton $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00021 * All rights reserved. 00022 * 00023 * The Original Code is: all of this file. 00024 * 00025 * Contributor(s): none yet. 00026 * 00027 * ***** END GPL LICENSE BLOCK ***** 00028 * return info about ID types 00029 */ 00030 00036 #include <stdlib.h> 00037 #include <string.h> 00038 00039 #include "DNA_ID.h" 00040 00041 #include "BKE_idcode.h" 00042 00043 typedef struct { 00044 unsigned short code; 00045 const char *name, *plural; 00046 00047 int flags; 00048 #define IDTYPE_FLAGS_ISLINKABLE (1<<0) 00049 } IDType; 00050 00051 /* plural need to match rna_main.c's MainCollectionDef */ 00052 static IDType idtypes[]= { 00053 { ID_AC, "Action", "actions", IDTYPE_FLAGS_ISLINKABLE}, 00054 { ID_AR, "Armature", "armatures", IDTYPE_FLAGS_ISLINKABLE}, 00055 { ID_BR, "Brush", "brushes", IDTYPE_FLAGS_ISLINKABLE}, 00056 { ID_CA, "Camera", "cameras", IDTYPE_FLAGS_ISLINKABLE}, 00057 { ID_CU, "Curve", "curves", IDTYPE_FLAGS_ISLINKABLE}, 00058 { ID_GD, "GPencil", "grease_pencil",IDTYPE_FLAGS_ISLINKABLE}, /* rename gpencil */ 00059 { ID_GR, "Group", "groups", IDTYPE_FLAGS_ISLINKABLE}, 00060 { ID_ID, "ID", "ids", 0}, /* plural is fake */ 00061 { ID_IM, "Image", "images", IDTYPE_FLAGS_ISLINKABLE}, 00062 { ID_IP, "Ipo", "ipos", IDTYPE_FLAGS_ISLINKABLE}, /* deprecated */ 00063 { ID_KE, "Key", "keys", 0}, 00064 { ID_LA, "Lamp", "lamps", IDTYPE_FLAGS_ISLINKABLE}, 00065 { ID_LI, "Library", "libraries", 0}, 00066 { ID_LT, "Lattice", "lattices", IDTYPE_FLAGS_ISLINKABLE}, 00067 { ID_MA, "Material", "materials", IDTYPE_FLAGS_ISLINKABLE}, 00068 { ID_MB, "Metaball", "metaballs", IDTYPE_FLAGS_ISLINKABLE}, 00069 { ID_ME, "Mesh", "meshes", IDTYPE_FLAGS_ISLINKABLE}, 00070 { ID_NT, "NodeTree", "node_groups", IDTYPE_FLAGS_ISLINKABLE}, 00071 { ID_OB, "Object", "objects", IDTYPE_FLAGS_ISLINKABLE}, 00072 { ID_PA, "ParticleSettings", "particles", 0}, 00073 { ID_SCE, "Scene", "scenes", IDTYPE_FLAGS_ISLINKABLE}, 00074 { ID_SCR, "Screen", "screens", 0}, 00075 { ID_SEQ, "Sequence", "sequences", 0}, /* not actually ID data */ 00076 { ID_SO, "Sound", "sounds", IDTYPE_FLAGS_ISLINKABLE}, 00077 { ID_TE, "Texture", "textures", IDTYPE_FLAGS_ISLINKABLE}, 00078 { ID_TXT, "Text", "texts", IDTYPE_FLAGS_ISLINKABLE}, 00079 { ID_VF, "VFont", "fonts", IDTYPE_FLAGS_ISLINKABLE}, 00080 { ID_WO, "World", "worlds", IDTYPE_FLAGS_ISLINKABLE}, 00081 { ID_WM, "WindowManager", "window_managers", 0}, 00082 }; 00083 static int nidtypes= sizeof(idtypes)/sizeof(idtypes[0]); 00084 00085 static IDType *idtype_from_name(const char *str) 00086 { 00087 int i= nidtypes; 00088 00089 while (i--) 00090 if (strcmp(str, idtypes[i].name)==0) 00091 return &idtypes[i]; 00092 00093 return NULL; 00094 } 00095 static IDType *idtype_from_code(int code) 00096 { 00097 int i= nidtypes; 00098 00099 while (i--) 00100 if (code==idtypes[i].code) 00101 return &idtypes[i]; 00102 00103 return NULL; 00104 } 00105 00106 int BKE_idcode_is_valid(int code) 00107 { 00108 return idtype_from_code(code)?1:0; 00109 } 00110 00111 int BKE_idcode_is_linkable(int code) { 00112 IDType *idt= idtype_from_code(code); 00113 return idt?(idt->flags&IDTYPE_FLAGS_ISLINKABLE):0; 00114 } 00115 00116 const char *BKE_idcode_to_name(int code) 00117 { 00118 IDType *idt= idtype_from_code(code); 00119 00120 return idt?idt->name:NULL; 00121 } 00122 00123 int BKE_idcode_from_name(const char *name) 00124 { 00125 IDType *idt= idtype_from_name(name); 00126 00127 return idt?idt->code:0; 00128 } 00129 00130 const char *BKE_idcode_to_name_plural(int code) 00131 { 00132 IDType *idt= idtype_from_code(code); 00133 00134 return idt?idt->plural:NULL; 00135 } 00136 00137 int BKE_idcode_iter_step(int *index) 00138 { 00139 return (*index < nidtypes) ? idtypes[(*index)++].code : 0; 00140 }