Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_add.c
| Context not available. | |||||
| #include "BKE_effect.h" | #include "BKE_effect.h" | ||||
| #include "BKE_font.h" | #include "BKE_font.h" | ||||
| #include "BKE_group.h" | #include "BKE_group.h" | ||||
| #include "BKE_gpencil.h" | |||||
| #include "BKE_lamp.h" | #include "BKE_lamp.h" | ||||
| #include "BKE_lattice.h" | #include "BKE_lattice.h" | ||||
| #include "BKE_layer.h" | #include "BKE_layer.h" | ||||
| Context not available. | |||||
| #include "ED_armature.h" | #include "ED_armature.h" | ||||
| #include "ED_curve.h" | #include "ED_curve.h" | ||||
| #include "ED_gpencil.h" | |||||
| #include "ED_mball.h" | #include "ED_mball.h" | ||||
| #include "ED_mesh.h" | #include "ED_mesh.h" | ||||
| #include "ED_node.h" | #include "ED_node.h" | ||||
| Context not available. | |||||
| ED_object_add_generic_props(ot, false); | ED_object_add_generic_props(ot, false); | ||||
| } | } | ||||
| /********************* Add Gpencil Operator ********************/ | |||||
| static int object_gpencil_add_exec(bContext *C, wmOperator *op) | |||||
| { | |||||
| Object *ob = CTX_data_active_object(C); | |||||
| bGPdata *gpd = (ob && (ob->type == OB_GPENCIL)) ? ob->data : NULL; | |||||
| const int type = RNA_enum_get(op->ptr, "type"); | |||||
| float loc[3], rot[3]; | |||||
| unsigned int layer; | |||||
| bool view_align = true; | |||||
| bool newob = false; | |||||
| /* Hack: Force view-align to be on by default | |||||
| * since it's not nice for adding shapes in 2D | |||||
| * for them to end up aligned oddly | |||||
| */ | |||||
| if (RNA_struct_property_is_set(op->ptr, "view_align") == false) | |||||
| RNA_boolean_set(op->ptr, "view_align", true); | |||||
| /* Note: We use 'Y' here (not 'Z'), as */ | |||||
| WM_operator_view3d_unit_defaults(C, op); | |||||
| if (!ED_object_add_generic_get_opts(C, op, 'Y', loc, rot, NULL, &layer, NULL)) | |||||
| return OPERATOR_CANCELLED; | |||||
| /* add new object if not currently editing a GP object, | |||||
| * or if "empty" was chosen (i.e. user wants a blank GP canvas) | |||||
| */ | |||||
| if ((gpd == NULL) || (GPENCIL_ANY_MODE(gpd) == false) || (type == GP_EMPTY)) { | |||||
| const char *ob_name = (type == GP_MONKEY) ? "Suzanne" : NULL; | |||||
| float radius = RNA_float_get(op->ptr, "radius"); | |||||
| ob = ED_object_add_type(C, OB_GPENCIL, ob_name, loc, rot, true, layer); | |||||
| gpd = ob->data; | |||||
| newob = true; | |||||
| BKE_object_obdata_size_init(ob, GP_OBGPENCIL_DEFAULT_SIZE * radius); | |||||
| } | |||||
| else { | |||||
| DEG_id_tag_update(&ob->id, OB_RECALC_DATA); | |||||
| WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_ADDED, NULL); | |||||
| } | |||||
| /* create relevant geometry */ | |||||
| switch (type) { | |||||
| case GP_MONKEY: | |||||
| { | |||||
| float radius = RNA_float_get(op->ptr, "radius"); | |||||
| float mat[4][4]; | |||||
| ED_object_new_primitive_matrix(C, ob, loc, rot, mat); | |||||
| mul_v3_fl(mat[0], radius); | |||||
| mul_v3_fl(mat[1], radius); | |||||
| mul_v3_fl(mat[2], radius); | |||||
| ED_gpencil_create_monkey(C, gpd, mat); | |||||
| break; | |||||
| } | |||||
| case GP_EMPTY: | |||||
| /* do nothing */ | |||||
| break; | |||||
| default: | |||||
| BKE_report(op->reports, RPT_WARNING, "Not implemented"); | |||||
| break; | |||||
| } | |||||
| /* if this is a new object, initialise default stuff (colors, etc.) */ | |||||
| if (newob) { | |||||
| ED_gpencil_add_defaults(C); | |||||
| } | |||||
| return OPERATOR_FINISHED; | |||||
| } | |||||
| void OBJECT_OT_gpencil_add(wmOperatorType *ot) | |||||
| { | |||||
| /* identifiers */ | |||||
| ot->name = "Add GPencil"; | |||||
| ot->description = "Add a grease pencil object to the scene"; | |||||
| ot->idname = "OBJECT_OT_gpencil_add"; | |||||
| /* api callbacks */ | |||||
| ot->invoke = WM_menu_invoke; | |||||
| ot->exec = object_gpencil_add_exec; | |||||
| ot->poll = ED_operator_scene_editable; | |||||
| /* flags */ | |||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | |||||
| /* properties */ | |||||
| ED_object_add_unit_props(ot); | |||||
| ED_object_add_generic_props(ot, false); | |||||
| ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_object_gpencil_type_items, 0, "Type", ""); | |||||
| } | |||||
| /********************* Add Lamp Operator ********************/ | /********************* Add Lamp Operator ********************/ | ||||
| static const char *get_lamp_defname(int type) | static const char *get_lamp_defname(int type) | ||||
| Context not available. | |||||
| } | } | ||||
| } | } | ||||
| /* remove as scene default annotation object */ | |||||
| if (ob->type == OB_GPENCIL) { | |||||
| Scene *scene_iter; | |||||
| for (scene_iter = bmain->scene.first; scene_iter; scene_iter = scene_iter->id.next) { | |||||
| if (scene->gp_object == ob) { | |||||
| scene->gp_object = NULL; | |||||
| } | |||||
| } | |||||
| } | |||||
| /* remove from current scene only */ | /* remove from current scene only */ | ||||
| ED_object_base_free_and_unlink(bmain, scene, ob); | ED_object_base_free_and_unlink(bmain, scene, ob); | ||||
| changed = true; | changed = true; | ||||
| Context not available. | |||||
| id_us_min(id); | id_us_min(id); | ||||
| } | } | ||||
| break; | break; | ||||
| case OB_GPENCIL: | |||||
| if (dupflag != 0) { | |||||
| ID_NEW_REMAP_US2(obn->data) | |||||
| else { | |||||
| obn->data = ID_NEW_SET(obn->data, BKE_gpencil_copy(bmain, obn->data)); | |||||
| didit = 1; | |||||
| } | |||||
| id_us_min(id); | |||||
| } | |||||
| break; | |||||
| } | } | ||||
| /* check if obdata is copied */ | /* check if obdata is copied */ | ||||
| Context not available. | |||||
| if (!ob || ID_IS_LINKED(ob)) return 0; | if (!ob || ID_IS_LINKED(ob)) return 0; | ||||
| if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_ARMATURE)) | if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_ARMATURE, OB_GPENCIL)) | ||||
| return ED_operator_screenactive(C); | return ED_operator_screenactive(C); | ||||
| else | else | ||||
| return 0; | return 0; | ||||
| Context not available. | |||||
| BKE_report(op->reports, RPT_ERROR, "Cannot edit external libdata"); | BKE_report(op->reports, RPT_ERROR, "Cannot edit external libdata"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| else if (ob->type == OB_GPENCIL) { | |||||
| bGPdata *gpd = (bGPdata *)ob->data; | |||||
| if ((!gpd) || GPENCIL_ANY_MODE(gpd)) { | |||||
| BKE_report(op->reports, RPT_ERROR, "This data does not support joining in this mode"); | |||||
| return OPERATOR_CANCELLED; | |||||
| } | |||||
| } | |||||
| if (ob->type == OB_MESH) | if (ob->type == OB_MESH) | ||||
| return join_mesh_exec(C, op); | return join_mesh_exec(C, op); | ||||
| Context not available. | |||||
| return join_curve_exec(C, op); | return join_curve_exec(C, op); | ||||
| else if (ob->type == OB_ARMATURE) | else if (ob->type == OB_ARMATURE) | ||||
| return join_armature_exec(C, op); | return join_armature_exec(C, op); | ||||
| else if (ob->type == OB_GPENCIL) | |||||
| return ED_gpencil_join_objects_exec(C, op); | |||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| Context not available. | |||||