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; | |||||
| int type = RNA_enum_get(op->ptr, "type"); | |||||
| unsigned int layer; | |||||
| float loc[3], rot[3]; | |||||
| WM_operator_view3d_unit_defaults(C, op); | |||||
| if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, NULL, &layer, NULL)) | |||||
| return OPERATOR_CANCELLED; | |||||
| ob = ED_object_add_type(C, OB_GPENCIL, NULL, loc, rot, false, layer); | |||||
| BKE_object_obdata_size_init(ob, GP_OBGPENCIL_DEFAULT_SIZE); | |||||
| /* if type is monkey, create a 2D Suzanne */ | |||||
| // TODO: create with offset to cursor? | |||||
| switch (type) { | |||||
| case GP_MONKEY: | |||||
| { | |||||
| ED_gpencil_create_monkey(C, ob->data); | |||||
| ED_object_rotation_from_view(C, rot, 'Y'); | |||||
| copy_v3_v3(ob->rot, rot); | |||||
| ED_gpencil_add_defaults(C); | |||||
| break; | |||||
| } | |||||
| case GP_EMPTY: | |||||
| /* do nothing */ | |||||
| ED_gpencil_add_defaults(C); | |||||
| break; | |||||
| default: | |||||
| BKE_report(op->reports, RPT_WARNING, "Not implemented"); | |||||
| break; | |||||
| } | |||||
| 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->exec = object_gpencil_add_exec; | |||||
| ot->poll = ED_operator_objectmode; | |||||
| /* 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. | |||||