4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * Contributor(s): Blender Foundation, 2009
25 * ***** END GPL LICENSE BLOCK *****
31 #include "DNA_modifier_types.h"
32 #include "DNA_object_types.h"
33 #include "DNA_scene_types.h"
35 #include "BLI_listbase.h"
37 #include "BKE_context.h"
38 #include "BKE_depsgraph.h"
39 #include "BKE_modifier.h"
41 #include "RNA_access.h"
42 #include "RNA_define.h"
43 #include "RNA_enum_types.h"
45 #include "ED_screen.h"
50 #include "object_intern.h"
52 /********************* add modifier operator ********************/
54 static int modifier_add_exec(bContext *C, wmOperator *op)
56 Scene *scene= CTX_data_scene(C);
57 Object *ob = CTX_data_active_object(C);
59 int type= RNA_enum_get(op->ptr, "type");
60 ModifierTypeInfo *mti = modifierType_getInfo(type);
62 if(mti->flags&eModifierTypeFlag_RequiresOriginalData) {
63 md = ob->modifiers.first;
65 while(md && modifierType_getInfo(md->type)->type==eModifierTypeType_OnlyDeform)
68 BLI_insertlinkbefore(&ob->modifiers, md, modifier_new(type));
71 BLI_addtail(&ob->modifiers, modifier_new(type));
73 DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
74 WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);
76 return OPERATOR_FINISHED;
79 void OBJECT_OT_modifier_add(wmOperatorType *ot)
82 ot->name= "Add Modifier";
83 ot->description = "Add a modifier to the active object.";
84 ot->idname= "OBJECT_OT_modifier_add";
87 ot->invoke= WM_menu_invoke;
88 ot->exec= modifier_add_exec;
90 ot->poll= ED_operator_object_active;
93 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
95 /* XXX only some types should be here */
96 RNA_def_enum(ot->srna, "type", modifier_type_items, 0, "Type", "");