Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_add.c
| Show First 20 Lines • Show All 1,651 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Collection *collection; | Collection *collection; | ||||
| ushort local_view_bits; | ushort local_view_bits; | ||||
| float loc[3], rot[3]; | float loc[3], rot[3]; | ||||
| PropertyRNA *prop_name = RNA_struct_find_property(op->ptr, "name"); | PropertyRNA *prop_name = RNA_struct_find_property(op->ptr, "name"); | ||||
| PropertyRNA *prop_location = RNA_struct_find_property(op->ptr, "location"); | PropertyRNA *prop_location = RNA_struct_find_property(op->ptr, "location"); | ||||
| PropertyRNA *prop_session_uuid = RNA_struct_find_property(op->ptr, "session_uuid"); | |||||
| bool update_location_if_necessary = false; | |||||
| if (RNA_property_is_set(op->ptr, prop_name)) { | if (RNA_property_is_set(op->ptr, prop_name)) { | ||||
| char name[MAX_ID_NAME - 2]; | char name[MAX_ID_NAME - 2]; | ||||
| RNA_property_string_get(op->ptr, prop_name, name); | RNA_property_string_get(op->ptr, prop_name, name); | ||||
| collection = (Collection *)BKE_libblock_find_name(bmain, ID_GR, name); | collection = (Collection *)BKE_libblock_find_name(bmain, ID_GR, name); | ||||
| update_location_if_necessary = true; | |||||
| } | |||||
| else if (RNA_property_is_set(op->ptr, prop_session_uuid)) { | |||||
| const uint32_t session_uuid = (uint32_t)RNA_property_int_get(op->ptr, prop_session_uuid); | |||||
| collection = (Collection *)BKE_libblock_find_session_uuid(bmain, ID_GR, session_uuid); | |||||
| update_location_if_necessary = true; | |||||
| } | |||||
| else { | |||||
| collection = BLI_findlink(&bmain->collections, RNA_enum_get(op->ptr, "collection")); | |||||
| } | |||||
| if (update_location_if_necessary) { | |||||
| int mval[2]; | int mval[2]; | ||||
| if (!RNA_property_is_set(op->ptr, prop_location) && object_add_drop_xy_get(C, op, &mval)) { | if (!RNA_property_is_set(op->ptr, prop_location) && object_add_drop_xy_get(C, op, &mval)) { | ||||
| ED_object_location_from_view(C, loc); | ED_object_location_from_view(C, loc); | ||||
| ED_view3d_cursor3d_position(C, mval, false, loc); | ED_view3d_cursor3d_position(C, mval, false, loc); | ||||
| RNA_property_float_set_array(op->ptr, prop_location, loc); | RNA_property_float_set_array(op->ptr, prop_location, loc); | ||||
| } | } | ||||
| } | } | ||||
| else { | |||||
| collection = BLI_findlink(&bmain->collections, RNA_enum_get(op->ptr, "collection")); | |||||
| } | |||||
| if (collection == NULL) { | if (collection == NULL) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, NULL, NULL, &local_view_bits, NULL)) { | if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, NULL, NULL, &local_view_bits, NULL)) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| Show All 18 Lines | |||||
| static int object_instance_add_invoke(bContext *C, wmOperator *op, const wmEvent *event) | static int object_instance_add_invoke(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| { | { | ||||
| if (!object_add_drop_xy_is_set(op)) { | if (!object_add_drop_xy_is_set(op)) { | ||||
| RNA_int_set(op->ptr, "drop_x", event->xy[0]); | RNA_int_set(op->ptr, "drop_x", event->xy[0]); | ||||
| RNA_int_set(op->ptr, "drop_y", event->xy[1]); | RNA_int_set(op->ptr, "drop_y", event->xy[1]); | ||||
| } | } | ||||
| if (!RNA_struct_property_is_set(op->ptr, "name")) { | if (!RNA_struct_property_is_set(op->ptr, "name") && | ||||
| !RNA_struct_property_is_set(op->ptr, "session_uuid")) { | |||||
| return WM_enum_search_invoke(C, op, event); | return WM_enum_search_invoke(C, op, event); | ||||
| } | } | ||||
| return op->type->exec(C, op); | return op->type->exec(C, op); | ||||
| } | } | ||||
| /* only used as menu */ | /* only used as menu */ | ||||
| void OBJECT_OT_collection_instance_add(wmOperatorType *ot) | void OBJECT_OT_collection_instance_add(wmOperatorType *ot) | ||||
| { | { | ||||
| Show All 17 Lines | RNA_def_string( | ||||
| ot->srna, "name", "Collection", MAX_ID_NAME - 2, "Name", "Collection name to add"); | ot->srna, "name", "Collection", MAX_ID_NAME - 2, "Name", "Collection name to add"); | ||||
| prop = RNA_def_enum(ot->srna, "collection", DummyRNA_NULL_items, 0, "Collection", ""); | prop = RNA_def_enum(ot->srna, "collection", DummyRNA_NULL_items, 0, "Collection", ""); | ||||
| RNA_def_enum_funcs(prop, RNA_collection_itemf); | RNA_def_enum_funcs(prop, RNA_collection_itemf); | ||||
| RNA_def_property_flag(prop, PROP_ENUM_NO_TRANSLATE); | RNA_def_property_flag(prop, PROP_ENUM_NO_TRANSLATE); | ||||
| ot->prop = prop; | ot->prop = prop; | ||||
| ED_object_add_generic_props(ot, false); | ED_object_add_generic_props(ot, false); | ||||
| object_add_drop_xy_props(ot); | object_add_drop_xy_props(ot); | ||||
| RNA_def_int(ot->srna, | |||||
| "session_uuid", | |||||
| 0, | |||||
| INT32_MIN, | |||||
| INT32_MAX, | |||||
| "Session UUID", | |||||
| "Session UUID of the collection to add", | |||||
| INT32_MIN, | |||||
| INT32_MAX); | |||||
mont29: Would rather have that before the call to `object_add_drop_xy_props` | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Add Data Instance Operator | /** \name Add Data Instance Operator | ||||
| * | * | ||||
| * Use for dropping ID's from the outliner. | * Use for dropping ID's from the outliner. | ||||
| ▲ Show 20 Lines • Show All 2,106 Lines • Show Last 20 Lines | |||||
Would rather have that before the call to object_add_drop_xy_props