Clean up in "add object" code:
* Get rid of ED_object_add_generic_invoke() and all invoke callbacks using it, it was doing nothing exec() callbacks would not do. In fact, its only action (setting part of common add ops properties, like loc, layers, etc.) was needed too by direct exec call, so it was done twice in case of using invoke()! * Replace custom invoke code for metaballs by WM_menu_invoke helper (as already used by lamps). * Add a new OBJECT_OT_empty_add op, to allow direct addition of empties of a given drawtype. * And some general code cleanup (like trailing spaces, empty lines, ...). Did quite a bunch of tests/verifications, but obviously could not tackle all possible scenarios... Anyway, if any, bugs should arize quite quickly (but I don’t expect any! :p ).
This commit is contained in:
@@ -192,7 +192,7 @@ class INFO_MT_mesh_add(Menu):
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
layout.operator_context = 'INVOKE_REGION_WIN'
|
||||
layout.operator_context = 'EXEC_REGION_WIN'
|
||||
layout.operator("mesh.primitive_plane_add", icon='MESH_PLANE', text="Plane")
|
||||
layout.operator("mesh.primitive_cube_add", icon='MESH_CUBE', text="Cube")
|
||||
layout.operator("mesh.primitive_circle_add", icon='MESH_CIRCLE', text="Circle")
|
||||
@@ -203,7 +203,7 @@ class INFO_MT_mesh_add(Menu):
|
||||
layout.separator()
|
||||
layout.operator("mesh.primitive_grid_add", icon='MESH_GRID', text="Grid")
|
||||
layout.operator("mesh.primitive_monkey_add", icon='MESH_MONKEY', text="Monkey")
|
||||
layout.operator("mesh.primitive_torus_add", text="Torus", icon='MESH_TORUS')
|
||||
layout.operator("mesh.primitive_torus_add", icon='MESH_TORUS', text="Torus")
|
||||
|
||||
|
||||
class INFO_MT_curve_add(Menu):
|
||||
@@ -213,7 +213,7 @@ class INFO_MT_curve_add(Menu):
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
layout.operator_context = 'INVOKE_REGION_WIN'
|
||||
layout.operator_context = 'EXEC_REGION_WIN'
|
||||
layout.operator("curve.primitive_bezier_curve_add", icon='CURVE_BEZCURVE', text="Bezier")
|
||||
layout.operator("curve.primitive_bezier_circle_add", icon='CURVE_BEZCIRCLE', text="Circle")
|
||||
layout.operator("curve.primitive_nurbs_curve_add", icon='CURVE_NCURVE', text="Nurbs Curve")
|
||||
@@ -221,6 +221,22 @@ class INFO_MT_curve_add(Menu):
|
||||
layout.operator("curve.primitive_nurbs_path_add", icon='CURVE_PATH', text="Path")
|
||||
|
||||
|
||||
class INFO_MT_surface_add(Menu):
|
||||
bl_idname = "INFO_MT_surface_add"
|
||||
bl_label = "Surface"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
layout.operator_context = 'EXEC_REGION_WIN'
|
||||
layout.operator("surface.primitive_nurbs_surface_curve_add", icon='SURFACE_NCURVE', text="NURBS Curve")
|
||||
layout.operator("surface.primitive_nurbs_surface_circle_add", icon='SURFACE_NCIRCLE', text="NURBS Circle")
|
||||
layout.operator("surface.primitive_nurbs_surface_surface_add", icon='SURFACE_NSURFACE', text="NURBS Surface")
|
||||
layout.operator("surface.primitive_nurbs_surface_cylinder_add", icon='SURFACE_NCYLINDER', text="NURBS Cylinder")
|
||||
layout.operator("surface.primitive_nurbs_surface_sphere_add", icon='SURFACE_NSPHERE', text="NURBS Sphere")
|
||||
layout.operator("surface.primitive_nurbs_surface_torus_add", icon='SURFACE_NTORUS', text="NURBS Torus")
|
||||
|
||||
|
||||
class INFO_MT_edit_curve_add(Menu):
|
||||
bl_idname = "INFO_MT_edit_curve_add"
|
||||
bl_label = "Add"
|
||||
@@ -229,7 +245,7 @@ class INFO_MT_edit_curve_add(Menu):
|
||||
is_surf = context.active_object.type == 'SURFACE'
|
||||
|
||||
layout = self.layout
|
||||
layout.operator_context = 'INVOKE_REGION_WIN'
|
||||
layout.operator_context = 'EXEC_REGION_WIN'
|
||||
|
||||
if is_surf:
|
||||
INFO_MT_surface_add.draw(self, context)
|
||||
@@ -237,22 +253,6 @@ class INFO_MT_edit_curve_add(Menu):
|
||||
INFO_MT_curve_add.draw(self, context)
|
||||
|
||||
|
||||
class INFO_MT_surface_add(Menu):
|
||||
bl_idname = "INFO_MT_surface_add"
|
||||
bl_label = "Surface"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
layout.operator_context = 'INVOKE_REGION_WIN'
|
||||
layout.operator("surface.primitive_nurbs_surface_curve_add", icon='SURFACE_NCURVE', text="NURBS Curve")
|
||||
layout.operator("surface.primitive_nurbs_surface_circle_add", icon='SURFACE_NCIRCLE', text="NURBS Circle")
|
||||
layout.operator("surface.primitive_nurbs_surface_surface_add", icon='SURFACE_NSURFACE', text="NURBS Surface")
|
||||
layout.operator("surface.primitive_nurbs_surface_cylinder_add", icon='SURFACE_NCYLINDER', text="NURBS Cylinder")
|
||||
layout.operator("surface.primitive_nurbs_surface_sphere_add", icon='SURFACE_NSPHERE', text="NURBS Sphere")
|
||||
layout.operator("surface.primitive_nurbs_surface_torus_add", icon='SURFACE_NTORUS', text="NURBS Torus")
|
||||
|
||||
|
||||
class INFO_MT_armature_add(Menu):
|
||||
bl_idname = "INFO_MT_armature_add"
|
||||
bl_label = "Armature"
|
||||
@@ -260,7 +260,7 @@ class INFO_MT_armature_add(Menu):
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
layout.operator_context = 'INVOKE_REGION_WIN'
|
||||
layout.operator_context = 'EXEC_REGION_WIN'
|
||||
layout.operator("object.armature_add", text="Single Bone", icon='BONE_DATA')
|
||||
|
||||
|
||||
@@ -284,23 +284,18 @@ class INFO_MT_add(Menu):
|
||||
#layout.operator_menu_enum("object.surface_add", "type", text="Surface", icon='OUTLINER_OB_SURFACE')
|
||||
layout.menu("INFO_MT_surface_add", icon='OUTLINER_OB_SURFACE')
|
||||
layout.operator_menu_enum("object.metaball_add", "type", text="Metaball", icon='OUTLINER_OB_META')
|
||||
# layout.operator_context = 'INVOKE_REGION_WIN'
|
||||
layout.operator("object.text_add", text="Text", icon='OUTLINER_OB_FONT')
|
||||
layout.separator()
|
||||
|
||||
layout.menu("INFO_MT_armature_add", icon='OUTLINER_OB_ARMATURE')
|
||||
# XXX Quick fix for [#32764].
|
||||
layout.operator_context = 'INVOKE_REGION_WIN'
|
||||
layout.operator("object.add", text="Lattice", icon='OUTLINER_OB_LATTICE').type = 'LATTICE'
|
||||
layout.operator("object.add", text="Empty", icon='OUTLINER_OB_EMPTY').type = 'EMPTY'
|
||||
layout.operator_context = 'EXEC_REGION_WIN'
|
||||
layout.operator_menu_enum("object.empty_add", "type", text="Empty", icon='OUTLINER_OB_EMPTY')
|
||||
layout.separator()
|
||||
|
||||
layout.operator("object.speaker_add", text="Speaker", icon='OUTLINER_OB_SPEAKER')
|
||||
layout.separator()
|
||||
|
||||
layout.operator("object.camera_add", text="Camera", icon='OUTLINER_OB_CAMERA')
|
||||
# layout.operator_context = 'EXEC_AREA'
|
||||
layout.operator_menu_enum("object.lamp_add", "type", text="Lamp", icon='OUTLINER_OB_LAMP')
|
||||
layout.separator()
|
||||
|
||||
@@ -308,7 +303,7 @@ class INFO_MT_add(Menu):
|
||||
layout.separator()
|
||||
|
||||
if(len(bpy.data.groups) > 10):
|
||||
layout.operator_context = 'INVOKE_DEFAULT'
|
||||
layout.operator_context = 'INVOKE_REGION_WIN'
|
||||
layout.operator("object.group_instance_add", text="Group Instance...", icon='OUTLINER_OB_EMPTY')
|
||||
else:
|
||||
layout.operator_menu_enum("object.group_instance_add", "group", text="Group Instance", icon='OUTLINER_OB_EMPTY')
|
||||
|
@@ -6589,7 +6589,6 @@ static int curvesurf_prim_add(bContext *C, wmOperator *op, int type, int isSurf)
|
||||
|
||||
/* rename here, the undo stack checks name for valid undo pushes */
|
||||
if (newob) {
|
||||
|
||||
if (obedit->type == OB_CURVE) {
|
||||
rename_id((ID *)obedit, get_curve_defname(type));
|
||||
rename_id((ID *)obedit->data, get_curve_defname(type));
|
||||
@@ -6645,7 +6644,6 @@ void CURVE_OT_primitive_bezier_curve_add(wmOperatorType *ot)
|
||||
ot->idname = "CURVE_OT_primitive_bezier_curve_add";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = ED_object_add_generic_invoke;
|
||||
ot->exec = add_primitive_bezier_exec;
|
||||
ot->poll = ED_operator_scene_editable;
|
||||
|
||||
@@ -6668,7 +6666,6 @@ void CURVE_OT_primitive_bezier_circle_add(wmOperatorType *ot)
|
||||
ot->idname = "CURVE_OT_primitive_bezier_circle_add";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = ED_object_add_generic_invoke;
|
||||
ot->exec = add_primitive_bezier_circle_exec;
|
||||
ot->poll = ED_operator_scene_editable;
|
||||
|
||||
@@ -6691,7 +6688,6 @@ void CURVE_OT_primitive_nurbs_curve_add(wmOperatorType *ot)
|
||||
ot->idname = "CURVE_OT_primitive_nurbs_curve_add";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = ED_object_add_generic_invoke;
|
||||
ot->exec = add_primitive_nurbs_curve_exec;
|
||||
ot->poll = ED_operator_scene_editable;
|
||||
|
||||
@@ -6714,7 +6710,6 @@ void CURVE_OT_primitive_nurbs_circle_add(wmOperatorType *ot)
|
||||
ot->idname = "CURVE_OT_primitive_nurbs_circle_add";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = ED_object_add_generic_invoke;
|
||||
ot->exec = add_primitive_nurbs_circle_exec;
|
||||
ot->poll = ED_operator_scene_editable;
|
||||
|
||||
@@ -6737,7 +6732,6 @@ void CURVE_OT_primitive_nurbs_path_add(wmOperatorType *ot)
|
||||
ot->idname = "CURVE_OT_primitive_nurbs_path_add";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = ED_object_add_generic_invoke;
|
||||
ot->exec = add_primitive_curve_path_exec;
|
||||
ot->poll = ED_operator_scene_editable;
|
||||
|
||||
@@ -6761,7 +6755,6 @@ void SURFACE_OT_primitive_nurbs_surface_curve_add(wmOperatorType *ot)
|
||||
ot->idname = "SURFACE_OT_primitive_nurbs_surface_curve_add";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = ED_object_add_generic_invoke;
|
||||
ot->exec = add_primitive_nurbs_surface_curve_exec;
|
||||
ot->poll = ED_operator_scene_editable;
|
||||
|
||||
@@ -6784,7 +6777,6 @@ void SURFACE_OT_primitive_nurbs_surface_circle_add(wmOperatorType *ot)
|
||||
ot->idname = "SURFACE_OT_primitive_nurbs_surface_circle_add";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = ED_object_add_generic_invoke;
|
||||
ot->exec = add_primitive_nurbs_surface_circle_exec;
|
||||
ot->poll = ED_operator_scene_editable;
|
||||
|
||||
@@ -6807,7 +6799,6 @@ void SURFACE_OT_primitive_nurbs_surface_surface_add(wmOperatorType *ot)
|
||||
ot->idname = "SURFACE_OT_primitive_nurbs_surface_surface_add";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = ED_object_add_generic_invoke;
|
||||
ot->exec = add_primitive_nurbs_surface_surface_exec;
|
||||
ot->poll = ED_operator_scene_editable;
|
||||
|
||||
@@ -6830,7 +6821,6 @@ void SURFACE_OT_primitive_nurbs_surface_cylinder_add(wmOperatorType *ot)
|
||||
ot->idname = "SURFACE_OT_primitive_nurbs_surface_cylinder_add";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = ED_object_add_generic_invoke;
|
||||
ot->exec = add_primitive_nurbs_surface_cylinder_exec;
|
||||
ot->poll = ED_operator_scene_editable;
|
||||
|
||||
@@ -6853,7 +6843,6 @@ void SURFACE_OT_primitive_nurbs_surface_sphere_add(wmOperatorType *ot)
|
||||
ot->idname = "SURFACE_OT_primitive_nurbs_surface_sphere_add";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = ED_object_add_generic_invoke;
|
||||
ot->exec = add_primitive_nurbs_surface_sphere_exec;
|
||||
ot->poll = ED_operator_scene_editable;
|
||||
|
||||
@@ -6876,7 +6865,6 @@ void SURFACE_OT_primitive_nurbs_surface_torus_add(wmOperatorType *ot)
|
||||
ot->idname = "SURFACE_OT_primitive_nurbs_surface_torus_add";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = ED_object_add_generic_invoke;
|
||||
ot->exec = add_primitive_nurbs_surface_torus_exec;
|
||||
ot->poll = ED_operator_scene_editable;
|
||||
|
||||
|
@@ -126,7 +126,6 @@ float ED_object_new_primitive_matrix(struct bContext *C, struct Object *editob,
|
||||
const float loc[3], const float rot[3], float primmat[][4]);
|
||||
|
||||
void ED_object_add_generic_props(struct wmOperatorType *ot, int do_editmode);
|
||||
int ED_object_add_generic_invoke(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
|
||||
int ED_object_add_generic_get_opts(struct bContext *C, struct wmOperator *op, float loc[3], float rot[3],
|
||||
int *enter_editmode, unsigned int *layer, int *is_view_aligned);
|
||||
|
||||
|
@@ -127,7 +127,6 @@ void MESH_OT_primitive_plane_add(wmOperatorType *ot)
|
||||
ot->idname = "MESH_OT_primitive_plane_add";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = ED_object_add_generic_invoke;
|
||||
ot->exec = add_primitive_plane_exec;
|
||||
ot->poll = ED_operator_scene_editable;
|
||||
|
||||
@@ -168,7 +167,6 @@ void MESH_OT_primitive_cube_add(wmOperatorType *ot)
|
||||
ot->idname = "MESH_OT_primitive_cube_add";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = ED_object_add_generic_invoke;
|
||||
ot->exec = add_primitive_cube_exec;
|
||||
ot->poll = ED_operator_scene_editable;
|
||||
|
||||
@@ -223,7 +221,6 @@ void MESH_OT_primitive_circle_add(wmOperatorType *ot)
|
||||
ot->idname = "MESH_OT_primitive_circle_add";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = ED_object_add_generic_invoke;
|
||||
ot->exec = add_primitive_circle_exec;
|
||||
ot->poll = ED_operator_scene_editable;
|
||||
|
||||
@@ -282,7 +279,6 @@ void MESH_OT_primitive_cylinder_add(wmOperatorType *ot)
|
||||
ot->idname = "MESH_OT_primitive_cylinder_add";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = ED_object_add_generic_invoke;
|
||||
ot->exec = add_primitive_cylinder_exec;
|
||||
ot->poll = ED_operator_scene_editable;
|
||||
|
||||
@@ -340,7 +336,6 @@ void MESH_OT_primitive_cone_add(wmOperatorType *ot)
|
||||
ot->idname = "MESH_OT_primitive_cone_add";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = ED_object_add_generic_invoke;
|
||||
ot->exec = add_primitive_cone_exec;
|
||||
ot->poll = ED_operator_scene_editable;
|
||||
|
||||
@@ -383,6 +378,7 @@ static int add_primitive_grid_exec(bContext *C, wmOperator *op)
|
||||
}
|
||||
|
||||
make_prim_finish(C, obedit, &state, enter_editmode);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
@@ -396,7 +392,6 @@ void MESH_OT_primitive_grid_add(wmOperatorType *ot)
|
||||
ot->idname = "MESH_OT_primitive_grid_add";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = ED_object_add_generic_invoke;
|
||||
ot->exec = add_primitive_grid_exec;
|
||||
ot->poll = ED_operator_scene_editable;
|
||||
|
||||
@@ -433,6 +428,7 @@ static int add_primitive_monkey_exec(bContext *C, wmOperator *op)
|
||||
}
|
||||
|
||||
make_prim_finish(C, obedit, &state, enter_editmode);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
@@ -444,7 +440,6 @@ void MESH_OT_primitive_monkey_add(wmOperatorType *ot)
|
||||
ot->idname = "MESH_OT_primitive_monkey_add";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = ED_object_add_generic_invoke;
|
||||
ot->exec = add_primitive_monkey_exec;
|
||||
ot->poll = ED_operator_scene_editable;
|
||||
|
||||
@@ -490,7 +485,6 @@ void MESH_OT_primitive_uv_sphere_add(wmOperatorType *ot)
|
||||
ot->idname = "MESH_OT_primitive_uv_sphere_add";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = ED_object_add_generic_invoke;
|
||||
ot->exec = add_primitive_uvsphere_exec;
|
||||
ot->poll = ED_operator_scene_editable;
|
||||
|
||||
@@ -543,7 +537,6 @@ void MESH_OT_primitive_ico_sphere_add(wmOperatorType *ot)
|
||||
ot->idname = "MESH_OT_primitive_ico_sphere_add";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = ED_object_add_generic_invoke;
|
||||
ot->exec = add_primitive_icosphere_exec;
|
||||
ot->poll = ED_operator_scene_editable;
|
||||
|
||||
|
@@ -43,6 +43,7 @@
|
||||
#include "DNA_meta_types.h"
|
||||
#include "DNA_object_fluidsim.h"
|
||||
#include "DNA_object_force.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_speaker_types.h"
|
||||
#include "DNA_vfont_types.h"
|
||||
@@ -138,6 +139,19 @@ static EnumPropertyItem field_type_items[] = {
|
||||
{0, NULL, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
/* Copy from rna_object.c */
|
||||
static EnumPropertyItem empty_drawtype_items[] = {
|
||||
{OB_PLAINAXES, "PLAIN_AXES", 0, "Plain Axes", ""},
|
||||
{OB_ARROWS, "ARROWS", 0, "Arrows", ""},
|
||||
{OB_SINGLE_ARROW, "SINGLE_ARROW", 0, "Single Arrow", ""},
|
||||
{OB_CIRCLE, "CIRCLE", 0, "Circle", ""},
|
||||
{OB_CUBE, "CUBE", 0, "Cube", ""},
|
||||
{OB_EMPTY_SPHERE, "SPHERE", 0, "Sphere", ""},
|
||||
{OB_EMPTY_CONE, "CONE", 0, "Cone", ""},
|
||||
{OB_EMPTY_IMAGE, "IMAGE", 0, "Image", ""},
|
||||
{0, NULL, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
/************************** Exported *****************************/
|
||||
|
||||
void ED_object_location_from_view(bContext *C, float loc[3])
|
||||
@@ -245,56 +259,31 @@ void ED_object_add_generic_props(wmOperatorType *ot, int do_editmode)
|
||||
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
|
||||
}
|
||||
|
||||
static void object_add_generic_invoke_options(bContext *C, wmOperator *op)
|
||||
{
|
||||
if (RNA_struct_find_property(op->ptr, "enter_editmode")) /* optional */
|
||||
if (!RNA_struct_property_is_set(op->ptr, "enter_editmode"))
|
||||
RNA_boolean_set(op->ptr, "enter_editmode", U.flag & USER_ADD_EDITMODE);
|
||||
|
||||
if (!RNA_struct_property_is_set(op->ptr, "location")) {
|
||||
float loc[3];
|
||||
|
||||
ED_object_location_from_view(C, loc);
|
||||
RNA_float_set_array(op->ptr, "location", loc);
|
||||
}
|
||||
|
||||
if (!RNA_struct_property_is_set(op->ptr, "layers")) {
|
||||
View3D *v3d = CTX_wm_view3d(C);
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
int a, values[20], layer;
|
||||
|
||||
if (v3d) {
|
||||
layer = (v3d->scenelock && !v3d->localvd) ? scene->layact : v3d->layact;
|
||||
}
|
||||
else {
|
||||
layer = scene->layact;
|
||||
}
|
||||
|
||||
for (a = 0; a < 20; a++) {
|
||||
values[a] = (layer & (1 << a));
|
||||
}
|
||||
|
||||
RNA_boolean_set_array(op->ptr, "layers", values);
|
||||
}
|
||||
}
|
||||
|
||||
int ED_object_add_generic_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
|
||||
{
|
||||
object_add_generic_invoke_options(C, op);
|
||||
return op->type->exec(C, op);
|
||||
}
|
||||
|
||||
int ED_object_add_generic_get_opts(bContext *C, wmOperator *op, float loc[3], float rot[3],
|
||||
int *enter_editmode, unsigned int *layer, int *is_view_aligned)
|
||||
{
|
||||
View3D *v3d = CTX_wm_view3d(C);
|
||||
int a, layer_values[20];
|
||||
int view_align;
|
||||
|
||||
*enter_editmode = FALSE;
|
||||
if (RNA_struct_find_property(op->ptr, "enter_editmode") && RNA_boolean_get(op->ptr, "enter_editmode")) {
|
||||
*enter_editmode = TRUE;
|
||||
/* Switch to Edit mode? */
|
||||
if (RNA_struct_find_property(op->ptr, "enter_editmode")) { /* optional */
|
||||
int _enter_editmode;
|
||||
if (!enter_editmode)
|
||||
enter_editmode = &_enter_editmode;
|
||||
|
||||
if (RNA_struct_property_is_set(op->ptr, "enter_editmode") && enter_editmode)
|
||||
*enter_editmode = RNA_boolean_get(op->ptr, "enter_editmode");
|
||||
else {
|
||||
*enter_editmode = U.flag & USER_ADD_EDITMODE;
|
||||
RNA_boolean_set(op->ptr, "enter_editmode", *enter_editmode);
|
||||
}
|
||||
}
|
||||
|
||||
/* Get layers! */
|
||||
{
|
||||
int a, layer_values[20];
|
||||
unsigned int _layer;
|
||||
if (!layer)
|
||||
layer = &_layer;
|
||||
|
||||
if (RNA_struct_property_is_set(op->ptr, "layers")) {
|
||||
RNA_boolean_get_array(op->ptr, "layers", layer_values);
|
||||
@@ -302,43 +291,68 @@ int ED_object_add_generic_get_opts(bContext *C, wmOperator *op, float loc[3], fl
|
||||
for (a = 0; a < 20; a++) {
|
||||
if (layer_values[a])
|
||||
*layer |= (1 << a);
|
||||
else
|
||||
*layer &= ~(1 << a);
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* not set, use the scenes layers */
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
if (v3d)
|
||||
*layer = (v3d->scenelock && !v3d->localvd) ? scene->layact : v3d->layact;
|
||||
else
|
||||
*layer = scene->layact;
|
||||
for (a = 0; a < 20; a++) {
|
||||
layer_values[a] = *layer & (1 << a);
|
||||
}
|
||||
RNA_boolean_set_array(op->ptr, "layers", layer_values);
|
||||
}
|
||||
|
||||
/* in local view we additionally add local view layers,
|
||||
* not part of operator properties */
|
||||
if (v3d && v3d->localvd)
|
||||
*layer |= v3d->lay;
|
||||
|
||||
if (RNA_struct_property_is_set(op->ptr, "rotation"))
|
||||
view_align = FALSE;
|
||||
else if (RNA_struct_property_is_set(op->ptr, "view_align"))
|
||||
view_align = RNA_boolean_get(op->ptr, "view_align");
|
||||
else {
|
||||
view_align = U.flag & USER_ADD_VIEWALIGNED;
|
||||
RNA_boolean_set(op->ptr, "view_align", view_align);
|
||||
}
|
||||
|
||||
if (view_align) {
|
||||
/* Location! */
|
||||
{
|
||||
float _loc[3];
|
||||
if (!loc)
|
||||
loc = _loc;
|
||||
|
||||
if (RNA_struct_property_is_set(op->ptr, "location")) {
|
||||
RNA_float_get_array(op->ptr, "location", loc);
|
||||
}
|
||||
else {
|
||||
ED_object_location_from_view(C, loc);
|
||||
RNA_float_set_array(op->ptr, "location", loc);
|
||||
}
|
||||
}
|
||||
|
||||
/* Rotation! */
|
||||
{
|
||||
int _is_view_aligned;
|
||||
float _rot[3];
|
||||
if (!is_view_aligned)
|
||||
is_view_aligned = &_is_view_aligned;
|
||||
if (!rot)
|
||||
rot = _rot;
|
||||
|
||||
if (RNA_struct_property_is_set(op->ptr, "rotation"))
|
||||
*is_view_aligned = FALSE;
|
||||
else if (RNA_struct_property_is_set(op->ptr, "view_align"))
|
||||
*is_view_aligned = RNA_boolean_get(op->ptr, "view_align");
|
||||
else {
|
||||
*is_view_aligned = U.flag & USER_ADD_VIEWALIGNED;
|
||||
RNA_boolean_set(op->ptr, "view_align", *is_view_aligned);
|
||||
}
|
||||
|
||||
if (*is_view_aligned) {
|
||||
ED_object_rotation_from_view(C, rot);
|
||||
RNA_float_set_array(op->ptr, "rotation", rot);
|
||||
}
|
||||
else
|
||||
RNA_float_get_array(op->ptr, "rotation", rot);
|
||||
}
|
||||
|
||||
if (is_view_aligned)
|
||||
*is_view_aligned = view_align;
|
||||
|
||||
RNA_float_get_array(op->ptr, "location", loc);
|
||||
|
||||
if (*layer == 0) {
|
||||
if (layer && *layer == 0) {
|
||||
BKE_report(op->reports, RPT_ERROR, "Property 'layer' has no values set");
|
||||
return 0;
|
||||
}
|
||||
@@ -405,9 +419,7 @@ void OBJECT_OT_add(wmOperatorType *ot)
|
||||
ot->idname = "OBJECT_OT_add";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = ED_object_add_generic_invoke;
|
||||
ot->exec = object_add_exec;
|
||||
|
||||
ot->poll = ED_operator_objectmode;
|
||||
|
||||
/* flags */
|
||||
@@ -420,57 +432,47 @@ void OBJECT_OT_add(wmOperatorType *ot)
|
||||
|
||||
/********************* Add Effector Operator ********************/
|
||||
|
||||
/* for effector add primitive operators */
|
||||
static Object *effector_add_type(bContext *C, wmOperator *op, int type)
|
||||
/* for object add operator */
|
||||
static int effector_add_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Object *ob;
|
||||
int enter_editmode;
|
||||
int type, enter_editmode;
|
||||
unsigned int layer;
|
||||
float loc[3], rot[3];
|
||||
float mat[4][4];
|
||||
|
||||
object_add_generic_invoke_options(C, op);
|
||||
|
||||
if (!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL))
|
||||
return NULL;
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
type = RNA_enum_get(op->ptr, "type");
|
||||
|
||||
if (type == PFIELD_GUIDE) {
|
||||
ob = ED_object_add_type(C, OB_CURVE, loc, rot, FALSE, layer);
|
||||
rename_id(&ob->id, "CurveGuide");
|
||||
if (!ob)
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
rename_id(&ob->id, "CurveGuide");
|
||||
((Curve *)ob->data)->flag |= CU_PATH | CU_3D;
|
||||
ED_object_enter_editmode(C, 0);
|
||||
ED_object_new_primitive_matrix(C, ob, loc, rot, mat);
|
||||
BLI_addtail(object_editcurve_get(ob), add_nurbs_primitive(C, ob, mat, CU_NURBS | CU_PRIM_PATH, 1));
|
||||
|
||||
if (!enter_editmode)
|
||||
ED_object_exit_editmode(C, EM_FREEDATA);
|
||||
}
|
||||
else {
|
||||
ob = ED_object_add_type(C, OB_EMPTY, loc, rot, FALSE, layer);
|
||||
rename_id(&ob->id, "Field");
|
||||
if (!ob)
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
switch (type) {
|
||||
case PFIELD_WIND:
|
||||
case PFIELD_VORTEX:
|
||||
rename_id(&ob->id, "Field");
|
||||
if (ELEM(type, PFIELD_WIND, PFIELD_VORTEX))
|
||||
ob->empty_drawtype = OB_SINGLE_ARROW;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ob->pd = object_add_collision_fields(type);
|
||||
|
||||
DAG_scene_sort(CTX_data_main(C), CTX_data_scene(C));
|
||||
|
||||
return ob;
|
||||
}
|
||||
|
||||
/* for object add operator */
|
||||
static int effector_add_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
if (effector_add_type(C, op, RNA_enum_get(op->ptr, "type")) == NULL)
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
@@ -482,9 +484,7 @@ void OBJECT_OT_effector_add(wmOperatorType *ot)
|
||||
ot->idname = "OBJECT_OT_effector_add";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = WM_menu_invoke;
|
||||
ot->exec = effector_add_exec;
|
||||
|
||||
ot->poll = ED_operator_objectmode;
|
||||
|
||||
/* flags */
|
||||
@@ -509,8 +509,6 @@ static int object_camera_add_exec(bContext *C, wmOperator *op)
|
||||
/* force view align for cameras */
|
||||
RNA_boolean_set(op->ptr, "view_align", TRUE);
|
||||
|
||||
object_add_generic_invoke_options(C, op);
|
||||
|
||||
if (!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL))
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
@@ -562,8 +560,6 @@ static int object_metaball_add_exec(bContext *C, wmOperator *op)
|
||||
float loc[3], rot[3];
|
||||
float mat[4][4];
|
||||
|
||||
object_add_generic_invoke_options(C, op); /* XXX these props don't get set right when only exec() is called */
|
||||
|
||||
if (!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL))
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
@@ -571,7 +567,8 @@ static int object_metaball_add_exec(bContext *C, wmOperator *op)
|
||||
obedit = ED_object_add_type(C, OB_MBALL, loc, rot, TRUE, layer);
|
||||
newob = 1;
|
||||
}
|
||||
else DAG_id_tag_update(&obedit->id, OB_RECALC_DATA);
|
||||
else
|
||||
DAG_id_tag_update(&obedit->id, OB_RECALC_DATA);
|
||||
|
||||
ED_object_new_primitive_matrix(C, obedit, loc, rot, mat);
|
||||
|
||||
@@ -587,25 +584,6 @@ static int object_metaball_add_exec(bContext *C, wmOperator *op)
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
static int object_metaball_add_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
|
||||
{
|
||||
Object *obedit = CTX_data_edit_object(C);
|
||||
uiPopupMenu *pup;
|
||||
uiLayout *layout;
|
||||
|
||||
object_add_generic_invoke_options(C, op);
|
||||
|
||||
pup = uiPupMenuBegin(C, op->type->name, ICON_NONE);
|
||||
layout = uiPupMenuLayout(pup);
|
||||
if (!obedit || obedit->type == OB_MBALL)
|
||||
uiItemsEnumO(layout, op->type->idname, "type");
|
||||
else
|
||||
uiItemsEnumO(layout, "OBJECT_OT_metaball_add", "type");
|
||||
uiPupMenuEnd(C, pup);
|
||||
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
void OBJECT_OT_metaball_add(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
@@ -614,14 +592,15 @@ void OBJECT_OT_metaball_add(wmOperatorType *ot)
|
||||
ot->idname = "OBJECT_OT_metaball_add";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = object_metaball_add_invoke;
|
||||
ot->invoke = WM_menu_invoke;/* object_metaball_add_invoke; */
|
||||
ot->exec = object_metaball_add_exec;
|
||||
ot->poll = ED_operator_scene_editable;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
|
||||
RNA_def_enum(ot->srna, "type", metaelem_type_items, 0, "Primitive", "");
|
||||
ot->prop = RNA_def_enum(ot->srna, "type", metaelem_type_items, 0, "Primitive", "");
|
||||
|
||||
ED_object_add_generic_props(ot, TRUE);
|
||||
}
|
||||
|
||||
@@ -634,7 +613,6 @@ static int object_add_text_exec(bContext *C, wmOperator *op)
|
||||
unsigned int layer;
|
||||
float loc[3], rot[3];
|
||||
|
||||
object_add_generic_invoke_options(C, op); /* XXX these props don't get set right when only exec() is called */
|
||||
if (!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL))
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
@@ -656,7 +634,6 @@ void OBJECT_OT_text_add(wmOperatorType *ot)
|
||||
ot->idname = "OBJECT_OT_text_add";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = ED_object_add_generic_invoke;
|
||||
ot->exec = object_add_text_exec;
|
||||
ot->poll = ED_operator_objectmode;
|
||||
|
||||
@@ -677,7 +654,6 @@ static int object_armature_add_exec(bContext *C, wmOperator *op)
|
||||
unsigned int layer;
|
||||
float loc[3], rot[3];
|
||||
|
||||
object_add_generic_invoke_options(C, op); /* XXX these props don't get set right when only exec() is called */
|
||||
if (!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL))
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
@@ -713,7 +689,6 @@ void OBJECT_OT_armature_add(wmOperatorType *ot)
|
||||
ot->idname = "OBJECT_OT_armature_add";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = ED_object_add_generic_invoke;
|
||||
ot->exec = object_armature_add_exec;
|
||||
ot->poll = ED_operator_objectmode;
|
||||
|
||||
@@ -722,6 +697,45 @@ void OBJECT_OT_armature_add(wmOperatorType *ot)
|
||||
ED_object_add_generic_props(ot, TRUE);
|
||||
}
|
||||
|
||||
/********************* Add Empty Operator ********************/
|
||||
|
||||
static int object_empty_add_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Object *ob;
|
||||
int type = RNA_enum_get(op->ptr, "type");
|
||||
unsigned int layer;
|
||||
float loc[3], rot[3];
|
||||
|
||||
if (!ED_object_add_generic_get_opts(C, op, loc, rot, NULL, &layer, NULL))
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
ob = ED_object_add_type(C, OB_EMPTY, loc, rot, FALSE, layer);
|
||||
ob->empty_drawtype = type;
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
void OBJECT_OT_empty_add(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
ot->name = "Add Empty";
|
||||
ot->description = "Add an empty object to the scene";
|
||||
ot->idname = "OBJECT_OT_empty_add";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = WM_menu_invoke;
|
||||
ot->exec = object_empty_add_exec;
|
||||
ot->poll = ED_operator_objectmode;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
|
||||
/* properties */
|
||||
ot->prop = RNA_def_enum(ot->srna, "type", empty_drawtype_items, 0, "Type", "");
|
||||
|
||||
ED_object_add_generic_props(ot, FALSE);
|
||||
}
|
||||
|
||||
/********************* Add Lamp Operator ********************/
|
||||
|
||||
static const char *get_lamp_defname(int type)
|
||||
@@ -743,12 +757,10 @@ static int object_lamp_add_exec(bContext *C, wmOperator *op)
|
||||
Object *ob;
|
||||
Lamp *la;
|
||||
int type = RNA_enum_get(op->ptr, "type");
|
||||
int enter_editmode;
|
||||
unsigned int layer;
|
||||
float loc[3], rot[3];
|
||||
|
||||
object_add_generic_invoke_options(C, op);
|
||||
if (!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL))
|
||||
if (!ED_object_add_generic_get_opts(C, op, loc, rot, NULL, &layer, NULL))
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
ob = ED_object_add_type(C, OB_LAMP, loc, rot, FALSE, layer);
|
||||
@@ -793,12 +805,10 @@ static int group_instance_add_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Group *group = BLI_findlink(&CTX_data_main(C)->group, RNA_enum_get(op->ptr, "group"));
|
||||
|
||||
int enter_editmode;
|
||||
unsigned int layer;
|
||||
float loc[3], rot[3];
|
||||
|
||||
object_add_generic_invoke_options(C, op);
|
||||
if (!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL))
|
||||
if (!ED_object_add_generic_get_opts(C, op, loc, rot, NULL, &layer, NULL))
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
if (group) {
|
||||
@@ -834,7 +844,6 @@ void OBJECT_OT_group_instance_add(wmOperatorType *ot)
|
||||
/* api callbacks */
|
||||
ot->invoke = WM_enum_search_invoke;
|
||||
ot->exec = group_instance_add_exec;
|
||||
|
||||
ot->poll = ED_operator_objectmode;
|
||||
|
||||
/* flags */
|
||||
@@ -852,13 +861,11 @@ void OBJECT_OT_group_instance_add(wmOperatorType *ot)
|
||||
static int object_speaker_add_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Object *ob;
|
||||
int enter_editmode;
|
||||
unsigned int layer;
|
||||
float loc[3], rot[3];
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
|
||||
object_add_generic_invoke_options(C, op);
|
||||
if (!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL))
|
||||
if (!ED_object_add_generic_get_opts(C, op, loc, rot, NULL, &layer, NULL))
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
ob = ED_object_add_type(C, OB_SPEAKER, loc, rot, FALSE, layer);
|
||||
|
@@ -112,6 +112,7 @@ void OBJECT_OT_add_named(struct wmOperatorType *ot);
|
||||
void OBJECT_OT_metaball_add(struct wmOperatorType *ot);
|
||||
void OBJECT_OT_text_add(struct wmOperatorType *ot);
|
||||
void OBJECT_OT_armature_add(struct wmOperatorType *ot);
|
||||
void OBJECT_OT_empty_add(struct wmOperatorType *ot);
|
||||
void OBJECT_OT_lamp_add(struct wmOperatorType *ot);
|
||||
void OBJECT_OT_effector_add(struct wmOperatorType *ot);
|
||||
void OBJECT_OT_camera_add(struct wmOperatorType *ot);
|
||||
|
@@ -113,6 +113,7 @@ void ED_operatortypes_object(void)
|
||||
WM_operatortype_append(OBJECT_OT_delete);
|
||||
WM_operatortype_append(OBJECT_OT_text_add);
|
||||
WM_operatortype_append(OBJECT_OT_armature_add);
|
||||
WM_operatortype_append(OBJECT_OT_empty_add);
|
||||
WM_operatortype_append(OBJECT_OT_lamp_add);
|
||||
WM_operatortype_append(OBJECT_OT_camera_add);
|
||||
WM_operatortype_append(OBJECT_OT_speaker_add);
|
||||
|
Reference in New Issue
Block a user