SHIFT+A add object back, no primitives in it though... later!
This commit is contained in:
Ton Roosendaal
2009-01-15 16:07:39 +00:00
parent 237cd7a7a7
commit 004eacad0c
4 changed files with 72 additions and 55 deletions

View File

@@ -266,55 +266,80 @@ void ED_object_base_init_from_view(Scene *scene, View3D *v3d, Base *base)
}
}
/* ******************* add object operator ****************** */
static EnumPropertyItem prop_object_types[] = {
{OB_EMPTY, "EMPTY", "Empty", ""},
{OB_MESH, "MESH", "Mesh", ""},
{OB_CURVE, "CURVE", "Curve", ""},
{OB_SURF, "SURFACE", "Surface", ""},
{OB_FONT, "TEXT", "Text", ""},
{OB_MBALL, "META", "Meta", ""},
{OB_LAMP, "LAMP", "Lamp", ""},
{OB_CAMERA, "CAMERA", "Camera", ""},
{OB_ARMATURE, "ARMATURE", "Armature", ""},
{OB_LATTICE, "LATTICE", "Lattice", ""},
{0, NULL, NULL, NULL}
};
void add_object_draw(Scene *scene, View3D *v3d, int type) /* for toolbox or menus, only non-editmode stuff */
{
Object *ob;
// ED_view3d_exit_paint_modes(C);
/* keep here to get things compile, remove later */
}
// XXX if (obedit) ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* freedata, and undo */
static int object_add_exec(bContext *C, wmOperator *op)
{
Scene *scene= CTX_data_scene(C);
ScrArea *sa= CTX_wm_area(C);
Object *ob;
View3D *v3d= NULL;
int type= RNA_int_get(op->ptr, "type");
/* hrms, this is editor level operator */
ED_view3d_exit_paint_modes(C);
if (CTX_data_edit_object(C))
ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* freedata, and undo */
/* deselects all, sets scene->basact */
ob= add_object(scene, type);
// ED_base_object_activate(C, BASACT);
/* editor level activate, notifiers */
ED_base_object_activate(C, BASACT);
/* more editor stuff */
if(sa && sa->spacetype==SPACE_VIEW3D)
v3d= sa->spacedata.first;
ED_object_base_init_from_view(scene, v3d, BASACT);
/* only undo pushes on objects without editmode... */
if(type==OB_EMPTY) BIF_undo_push("Add Empty");
else if(type==OB_LAMP) {
BIF_undo_push("Add Lamp");
reshadeall_displist(scene); /* only frees */
}
else if(type==OB_LATTICE) BIF_undo_push("Add Lattice");
else if(type==OB_CAMERA) BIF_undo_push("Add Camera");
allqueue(REDRAWVIEW3D, 0);
// XXX redraw_test_buttons(OBACT);
allqueue(REDRAWALL, 0);
// XXX deselect_all_area_oops();
// XXX set_select_flag_oops();
DAG_scene_sort(scene);
allqueue(REDRAWINFO, 1); /* 1, because header->win==0! */
}
void add_objectLamp(Scene *scene, View3D *v3d, short type)
{
Lamp *la;
if(scene->obedit==NULL) { // XXX get from context
add_object_draw(scene, v3d, OB_LAMP);
ED_object_base_init_from_view(scene, v3d, BASACT);
}
la = BASACT->object->data;
la->type = type;
allqueue(REDRAWALL, 0);
return OPERATOR_FINISHED;
}
void OBJECT_OT_object_add(wmOperatorType *ot)
{
PropertyRNA *prop;
/* identifiers */
ot->name= "Add Object";
ot->idname= "OBJECT_OT_object_add";
/* api callbacks */
ot->invoke= WM_menu_invoke;
ot->exec= object_add_exec;
ot->poll= ED_operator_scene_editable;
ot->flag= OPTYPE_REGISTER;
prop = RNA_def_property(ot->srna, "type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, prop_object_types);
}
/* ******************************* */
/* remove base from a specific scene */
/* note: now unlinks constraints as well */
void ED_base_object_free_and_unlink(Scene *scene, Base *base)
@@ -1138,18 +1163,6 @@ void OBJECT_OT_clear_track(wmOperatorType *ot)
/* ***************************** */
/* ****** Select by Type ****** */
static EnumPropertyItem prop_select_object_types[] = {
{OB_EMPTY, "EMPTY", "Empty", ""},
{OB_MESH, "MESH", "Mesh", ""},
{OB_CURVE, "CURVE", "Curve", ""},
{OB_SURF, "SURFACE", "Surface", ""},
{OB_FONT, "TEXT", "Text", ""},
{OB_MBALL, "META", "Meta", ""},
{OB_LAMP, "LAMP", "Lamp", ""},
{OB_CAMERA, "CAMERA", "Camera", ""},
{OB_LATTICE, "LATTICE", "Lattice", ""},
{0, NULL, NULL, NULL}
};
static int object_select_by_type_exec(bContext *C, wmOperator *op)
{
@@ -1184,7 +1197,7 @@ void OBJECT_OT_select_by_type(wmOperatorType *ot)
ot->poll= ED_operator_scene_editable;
prop = RNA_def_property(ot->srna, "type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, prop_select_object_types);
RNA_def_property_enum_items(prop, prop_object_types);
}
/* ****** selection by links *******/

View File

@@ -63,7 +63,7 @@ void OBJECT_OT_set_slowparent(struct wmOperatorType *ot);
void OBJECT_OT_clear_slowparent(struct wmOperatorType *ot);
void OBJECT_OT_set_center(struct wmOperatorType *ot);
void OBJECT_OT_make_dupli_real(struct wmOperatorType *ot);
void OBJECT_OT_object_add(struct wmOperatorType *ot);
/* editlattice.c */
void free_editLatt(Object *ob);

View File

@@ -84,6 +84,7 @@ void ED_operatortypes_object(void)
WM_operatortype_append(OBJECT_OT_clear_slowparent);
WM_operatortype_append(OBJECT_OT_set_center);
WM_operatortype_append(OBJECT_OT_make_dupli_real);
WM_operatortype_append(OBJECT_OT_object_add);
}
void ED_keymap_object(wmWindowManager *wm)
@@ -116,6 +117,9 @@ void ED_keymap_object(wmWindowManager *wm)
WM_keymap_verify_item(keymap, "OBJECT_OT_clear_restrictview", HKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_verify_item(keymap, "OBJECT_OT_set_restrictview", HKEY, KM_PRESS, 0, 0);
// RNA_int_set(WM_keymap_add_item(keymap, "OBJECT_OT_viewzoom", PADPLUSKEY, KM_PRESS, 0, 0)->ptr, "delta", 1);
WM_keymap_verify_item(keymap, "OBJECT_OT_object_add", AKEY, KM_PRESS, KM_SHIFT, 0);
}

View File

@@ -195,14 +195,14 @@ int WM_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
PropertyRNA *prop= RNA_struct_find_property(op->ptr, "type");
const EnumPropertyItem *item;
int totitem, i, len= strlen(op->type->name) + 5;
int totitem, i, len= strlen(op->type->name) + 8;
char *menu, *p;
if(prop) {
RNA_property_enum_items(op->ptr, prop, &item, &totitem);
for (i=0; i<totitem; i++)
len+= strlen(item[i].name) + 5;
len+= strlen(item[i].name) + 8;
menu= MEM_callocN(len, "string");