Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gpencil/gpencil_data.c
| Show First 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | |||||
| #include "gpencil_intern.h" | #include "gpencil_intern.h" | ||||
| /* ************************************************ */ | /* ************************************************ */ | ||||
| /* Datablock Operators */ | /* Datablock Operators */ | ||||
| /* ******************* Add New Data ************************ */ | /* ******************* Add New Data ************************ */ | ||||
| static bool gp_data_add_poll(bContext *C) | static bool gp_data_add_poll(bContext *C) | ||||
| { | { | ||||
| Object *obact = CTX_data_active_object(C); | |||||
| if (obact && obact->type == OB_GPENCIL) { | |||||
| if (obact->mode != OB_MODE_OBJECT) { | |||||
| return false; | |||||
| } | |||||
| } | |||||
| /* the base line we have is that we have somewhere to add Grease Pencil data */ | /* the base line we have is that we have somewhere to add Grease Pencil data */ | ||||
| return ED_gpencil_data_get_pointers(C, NULL) != NULL; | return ED_annotation_data_get_pointers(C, NULL) != NULL; | ||||
| } | } | ||||
| /* add new datablock - wrapper around API */ | /* add new datablock - wrapper around API */ | ||||
| static int gp_data_add_exec(bContext *C, wmOperator *op) | static int gp_data_add_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| PointerRNA gpd_owner = {NULL}; | PointerRNA gpd_owner = {NULL}; | ||||
| bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, &gpd_owner); | bGPdata **gpd_ptr = ED_annotation_data_get_pointers(C, &gpd_owner); | ||||
| bool is_annotation = ED_gpencil_data_owner_is_annotation(&gpd_owner); | |||||
| if (gpd_ptr == NULL) { | if (gpd_ptr == NULL) { | ||||
| BKE_report(op->reports, RPT_ERROR, "Nowhere for grease pencil data to go"); | BKE_report(op->reports, RPT_ERROR, "Nowhere for grease pencil data to go"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| else { | |||||
| /* decrement user count and add new datablock */ | /* decrement user count and add new datablock */ | ||||
| /* TODO: if a datablock exists, | /* TODO: if a datablock exists, | ||||
| * we should make a copy of it instead of starting fresh (as in other areas) */ | * we should make a copy of it instead of starting fresh (as in other areas) */ | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| /* decrement user count of old GP datablock */ | /* decrement user count of old GP datablock */ | ||||
| if (*gpd_ptr) { | if (*gpd_ptr) { | ||||
| bGPdata *gpd = (*gpd_ptr); | bGPdata *gpd = (*gpd_ptr); | ||||
| id_us_min(&gpd->id); | id_us_min(&gpd->id); | ||||
| } | } | ||||
| /* Add new datablock, with a single layer ready to use | /* Add new datablock, with a single layer ready to use | ||||
| * (so users don't have to perform an extra step). */ | * (so users don't have to perform an extra step). */ | ||||
| if (is_annotation) { | |||||
| bGPdata *gpd = BKE_gpencil_data_addnew(bmain, DATA_("Annotations")); | bGPdata *gpd = BKE_gpencil_data_addnew(bmain, DATA_("Annotations")); | ||||
| *gpd_ptr = gpd; | *gpd_ptr = gpd; | ||||
| /* tag for annotations */ | /* tag for annotations */ | ||||
| gpd->flag |= GP_DATA_ANNOTATIONS; | gpd->flag |= GP_DATA_ANNOTATIONS; | ||||
| /* add new layer (i.e. a "note") */ | /* add new layer (i.e. a "note") */ | ||||
| BKE_gpencil_layer_addnew(*gpd_ptr, DATA_("Note"), true); | BKE_gpencil_layer_addnew(*gpd_ptr, DATA_("Note"), true); | ||||
| } | |||||
| else { | |||||
| /* GP Object Case - This shouldn't happen! */ | |||||
| *gpd_ptr = BKE_gpencil_data_addnew(bmain, DATA_("GPencil")); | |||||
| /* add default sets of colors and brushes */ | |||||
| Object *ob = CTX_data_active_object(C); | |||||
| ED_gpencil_add_defaults(C, ob); | |||||
| /* add new layer */ | |||||
| BKE_gpencil_layer_addnew(*gpd_ptr, DATA_("GP_Layer"), true); | |||||
| } | |||||
| } | |||||
| /* notifiers */ | /* notifiers */ | ||||
| WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); | WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void GPENCIL_OT_data_add(wmOperatorType *ot) | void GPENCIL_OT_annotation_add(wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Grease Pencil Add New"; | ot->name = "Annotation Add New"; | ||||
| ot->idname = "GPENCIL_OT_data_add"; | ot->idname = "GPENCIL_OT_annotation_add"; | ||||
| ot->description = "Add new Grease Pencil data-block"; | ot->description = "Add new Annotation data-block"; | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| /* callbacks */ | /* callbacks */ | ||||
| ot->exec = gp_data_add_exec; | ot->exec = gp_data_add_exec; | ||||
| ot->poll = gp_data_add_poll; | ot->poll = gp_data_add_poll; | ||||
| } | } | ||||
| /* ******************* Unlink Data ************************ */ | /* ******************* Unlink Data ************************ */ | ||||
| /* poll callback for adding data/layers - special */ | /* poll callback for adding data/layers - special */ | ||||
| static bool gp_data_unlink_poll(bContext *C) | static bool gp_data_unlink_poll(bContext *C) | ||||
| { | { | ||||
| bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, NULL); | bGPdata **gpd_ptr = ED_annotation_data_get_pointers(C, NULL); | ||||
| /* only unlink annotation datablocks */ | /* only unlink annotation datablocks */ | ||||
| if ((gpd_ptr != NULL) && (*gpd_ptr != NULL)) { | if ((gpd_ptr != NULL) && (*gpd_ptr != NULL)) { | ||||
| bGPdata *gpd = (*gpd_ptr); | bGPdata *gpd = (*gpd_ptr); | ||||
| if ((gpd->flag & GP_DATA_ANNOTATIONS) == 0) { | if ((gpd->flag & GP_DATA_ANNOTATIONS) == 0) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| /* if we have access to some active data, make sure there's a datablock before enabling this */ | /* if we have access to some active data, make sure there's a datablock before enabling this */ | ||||
| return (gpd_ptr && *gpd_ptr); | return (gpd_ptr && *gpd_ptr); | ||||
| } | } | ||||
| /* unlink datablock - wrapper around API */ | /* unlink datablock - wrapper around API */ | ||||
| static int gp_data_unlink_exec(bContext *C, wmOperator *op) | static int gp_data_unlink_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, NULL); | bGPdata **gpd_ptr = ED_annotation_data_get_pointers(C, NULL); | ||||
| if (gpd_ptr == NULL) { | if (gpd_ptr == NULL) { | ||||
| BKE_report(op->reports, RPT_ERROR, "Nowhere for grease pencil data to go"); | BKE_report(op->reports, RPT_ERROR, "Nowhere for grease pencil data to go"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| else { | else { | ||||
| /* just unlink datablock now, decreasing its user count */ | /* just unlink datablock now, decreasing its user count */ | ||||
| bGPdata *gpd = (*gpd_ptr); | bGPdata *gpd = (*gpd_ptr); | ||||
| Show All 24 Lines | |||||
| /* ************************************************ */ | /* ************************************************ */ | ||||
| /* Layer Operators */ | /* Layer Operators */ | ||||
| /* ******************* Add New Layer ************************ */ | /* ******************* Add New Layer ************************ */ | ||||
| /* add new layer - wrapper around API */ | /* add new layer - wrapper around API */ | ||||
| static int gp_layer_add_exec(bContext *C, wmOperator *op) | static int gp_layer_add_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| const int is_annotation = RNA_boolean_get(op->ptr, "is_annotation"); | |||||
| PointerRNA gpd_owner = {NULL}; | PointerRNA gpd_owner = {NULL}; | ||||
| bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, &gpd_owner); | Main *bmain = CTX_data_main(C); | ||||
| bool is_annotation = ED_gpencil_data_owner_is_annotation(&gpd_owner); | bGPdata *gpd = NULL; | ||||
| if (is_annotation) { | |||||
| bGPdata **gpd_ptr = ED_annotation_data_get_pointers(C, &gpd_owner); | |||||
| /* if there's no existing Grease-Pencil data there, add some */ | /* if there's no existing Grease-Pencil data there, add some */ | ||||
| if (gpd_ptr == NULL) { | if (gpd_ptr == NULL) { | ||||
| BKE_report(op->reports, RPT_ERROR, "Nowhere for grease pencil data to go"); | BKE_report(op->reports, RPT_ERROR, "Nowhere for grease pencil data to go"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| if (*gpd_ptr == NULL) { | |||||
| Main *bmain = CTX_data_main(C); | |||||
| if (is_annotation) { | |||||
| /* Annotations */ | /* Annotations */ | ||||
| if (*gpd_ptr == NULL) { | |||||
| *gpd_ptr = BKE_gpencil_data_addnew(bmain, DATA_("Annotations")); | *gpd_ptr = BKE_gpencil_data_addnew(bmain, DATA_("Annotations")); | ||||
| } | |||||
| /* mark as annotation */ | /* mark as annotation */ | ||||
| (*gpd_ptr)->flag |= GP_DATA_ANNOTATIONS; | (*gpd_ptr)->flag |= GP_DATA_ANNOTATIONS; | ||||
| BKE_gpencil_layer_addnew(*gpd_ptr, DATA_("Note"), true); | |||||
| gpd = *gpd_ptr; | |||||
| } | } | ||||
| else { | else { | ||||
| /* GP Object */ | /* GP Object */ | ||||
| /* NOTE: This shouldn't actually happen in practice */ | |||||
| *gpd_ptr = BKE_gpencil_data_addnew(bmain, DATA_("GPencil")); | |||||
| /* add default sets of colors and brushes */ | |||||
| Object *ob = CTX_data_active_object(C); | Object *ob = CTX_data_active_object(C); | ||||
| ED_gpencil_add_defaults(C, ob); | if ((ob != NULL) && (ob->type == OB_GPENCIL)) { | ||||
| } | gpd = (bGPdata *)ob->data; | ||||
| } | BKE_gpencil_layer_addnew(gpd, DATA_("GP_Layer"), true); | ||||
| /* add new layer now */ | |||||
| if (is_annotation) { | |||||
| BKE_gpencil_layer_addnew(*gpd_ptr, DATA_("Note"), true); | |||||
| } | } | ||||
| else { | |||||
| BKE_gpencil_layer_addnew(*gpd_ptr, DATA_("GP_Layer"), true); | |||||
| } | } | ||||
| /* notifiers */ | /* notifiers */ | ||||
| bGPdata *gpd = *gpd_ptr; | if (gpd) { | ||||
| DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE); | DEG_id_tag_update(&gpd->id, | ||||
| ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE); | |||||
| } | |||||
| WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); | WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void GPENCIL_OT_layer_add(wmOperatorType *ot) | void GPENCIL_OT_layer_add(wmOperatorType *ot) | ||||
| { | { | ||||
| PropertyRNA *prop; | |||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Add New Layer"; | ot->name = "Add New Layer"; | ||||
| ot->idname = "GPENCIL_OT_layer_add"; | ot->idname = "GPENCIL_OT_layer_add"; | ||||
| ot->description = "Add new layer or note for the active data-block"; | ot->description = "Add new layer or note for the active data-block"; | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| /* callbacks */ | /* callbacks */ | ||||
| ot->exec = gp_layer_add_exec; | ot->exec = gp_layer_add_exec; | ||||
| ot->poll = gp_add_poll; | ot->poll = gp_add_poll; | ||||
| prop = RNA_def_boolean(ot->srna, "is_annotation", false, "Annotation", ""); | |||||
dfelinto: See my comment about is_annotation elsewhere | |||||
| RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); | |||||
| } | } | ||||
| static bool gp_add_annotation_poll(bContext *C) | |||||
| { | |||||
| return ED_annotation_data_get_pointers(C, NULL) != NULL; | |||||
| } | |||||
| void GPENCIL_OT_layer_annotation_add(wmOperatorType *ot) | |||||
| { | |||||
| PropertyRNA *prop; | |||||
| /* identifiers */ | |||||
| ot->name = "Add New Annotation Layer"; | |||||
| ot->idname = "GPENCIL_OT_layer_annotation_add"; | |||||
| ot->description = "Add new Annotation layer or note for the active data-block"; | |||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | |||||
| /* callbacks */ | |||||
| ot->exec = gp_layer_add_exec; | |||||
| ot->poll = gp_add_annotation_poll; | |||||
| prop = RNA_def_boolean(ot->srna, "is_annotation", true, "Annotation", ""); | |||||
| RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); | |||||
| } | |||||
| /* ******************* Remove Active Layer ************************* */ | /* ******************* Remove Active Layer ************************* */ | ||||
| static int gp_layer_remove_exec(bContext *C, wmOperator *op) | static int gp_layer_remove_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| bGPdata *gpd = ED_gpencil_data_get_active(C); | const int is_annotation = RNA_boolean_get(op->ptr, "is_annotation"); | ||||
| bGPdata *gpd = (!is_annotation) ? ED_gpencil_data_get_active(C) : | |||||
| ED_annotation_data_get_active(C); | |||||
| bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd); | bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd); | ||||
| /* sanity checks */ | /* sanity checks */ | ||||
| if (ELEM(NULL, gpd, gpl)) { | if (ELEM(NULL, gpd, gpl)) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| if (gpl->flag & GP_LAYER_LOCKED) { | if (gpl->flag & GP_LAYER_LOCKED) { | ||||
| Show All 19 Lines | static int gp_layer_remove_exec(bContext *C, wmOperator *op) | ||||
| DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY); | DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY); | ||||
| WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); | WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void GPENCIL_OT_layer_remove(wmOperatorType *ot) | void GPENCIL_OT_layer_remove(wmOperatorType *ot) | ||||
| { | { | ||||
| PropertyRNA *prop; | |||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Remove Layer"; | ot->name = "Remove Layer"; | ||||
| ot->idname = "GPENCIL_OT_layer_remove"; | ot->idname = "GPENCIL_OT_layer_remove"; | ||||
| ot->description = "Remove active Grease Pencil layer"; | ot->description = "Remove active Grease Pencil layer"; | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| /* callbacks */ | /* callbacks */ | ||||
| ot->exec = gp_layer_remove_exec; | ot->exec = gp_layer_remove_exec; | ||||
| ot->poll = gp_active_layer_poll; | ot->poll = gp_active_layer_poll; | ||||
| prop = RNA_def_boolean(ot->srna, "is_annotation", false, "Annotation", ""); | |||||
| RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); | |||||
| } | |||||
| static bool gp_active_layer_annotation_poll(bContext *C) | |||||
| { | |||||
| bGPdata *gpd = ED_annotation_data_get_active(C); | |||||
| bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd); | |||||
| return (gpl != NULL); | |||||
| } | } | ||||
| void GPENCIL_OT_layer_annotation_remove(wmOperatorType *ot) | |||||
| { | |||||
| PropertyRNA *prop; | |||||
| /* identifiers */ | |||||
| ot->name = "Remove Annotation Layer"; | |||||
| ot->idname = "GPENCIL_OT_layer_annotation_remove"; | |||||
| ot->description = "Remove active Annotation layer"; | |||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | |||||
| /* callbacks */ | |||||
| ot->exec = gp_layer_remove_exec; | |||||
| ot->poll = gp_active_layer_annotation_poll; | |||||
| prop = RNA_def_boolean(ot->srna, "is_annotation", true, "Annotation", ""); | |||||
dfelintoUnsubmitted Not Done Inline ActionsThis makes no sense. When would this operator be called for something that is not an annotation? For the users (Python developers anyways) it shows as: bpy.ops.gpencil.layer_annotation_remove(is_annotation=True) Confusing, right? I know what you mean to do, but you need to either have its own dedicated _exec function that then calls gp_layer_remove_exec or to get the operator name (see collection_objects_select_exec). dfelinto: This makes no sense. When would this operator be called for something that is not an annotation? | |||||
| RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); | |||||
| } | |||||
| /* ******************* Move Layer Up/Down ************************** */ | /* ******************* Move Layer Up/Down ************************** */ | ||||
| enum { | enum { | ||||
| GP_LAYER_MOVE_UP = -1, | GP_LAYER_MOVE_UP = -1, | ||||
| GP_LAYER_MOVE_DOWN = 1, | GP_LAYER_MOVE_DOWN = 1, | ||||
| }; | }; | ||||
| static int gp_layer_move_exec(bContext *C, wmOperator *op) | static int gp_layer_move_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| bGPdata *gpd = ED_gpencil_data_get_active(C); | const int is_annotation = RNA_boolean_get(op->ptr, "is_annotation"); | ||||
| bGPdata *gpd = (!is_annotation) ? ED_gpencil_data_get_active(C) : | |||||
| ED_annotation_data_get_active(C); | |||||
| bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd); | bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd); | ||||
| const int direction = RNA_enum_get(op->ptr, "type") * -1; | const int direction = RNA_enum_get(op->ptr, "type") * -1; | ||||
| /* sanity checks */ | /* sanity checks */ | ||||
| if (ELEM(NULL, gpd, gpl)) { | if (ELEM(NULL, gpd, gpl)) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| BLI_assert(ELEM(direction, -1, 0, 1)); /* we use value below */ | BLI_assert(ELEM(direction, -1, 0, 1)); /* we use value below */ | ||||
| if (BLI_listbase_link_move(&gpd->layers, gpl, direction)) { | if (BLI_listbase_link_move(&gpd->layers, gpl, direction)) { | ||||
| DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY); | DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY); | ||||
| WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); | WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); | ||||
| } | } | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void GPENCIL_OT_layer_move(wmOperatorType *ot) | void GPENCIL_OT_layer_move(wmOperatorType *ot) | ||||
| { | { | ||||
| PropertyRNA *prop; | |||||
| static const EnumPropertyItem slot_move[] = { | static const EnumPropertyItem slot_move[] = { | ||||
| {GP_LAYER_MOVE_UP, "UP", 0, "Up", ""}, | {GP_LAYER_MOVE_UP, "UP", 0, "Up", ""}, | ||||
| {GP_LAYER_MOVE_DOWN, "DOWN", 0, "Down", ""}, | {GP_LAYER_MOVE_DOWN, "DOWN", 0, "Down", ""}, | ||||
| {0, NULL, 0, NULL, NULL}, | {0, NULL, 0, NULL, NULL}, | ||||
| }; | }; | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Move Grease Pencil Layer"; | ot->name = "Move Grease Pencil Layer"; | ||||
| ot->idname = "GPENCIL_OT_layer_move"; | ot->idname = "GPENCIL_OT_layer_move"; | ||||
| ot->description = "Move the active Grease Pencil layer up/down in the list"; | ot->description = "Move the active Grease Pencil layer up/down in the list"; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->exec = gp_layer_move_exec; | ot->exec = gp_layer_move_exec; | ||||
| ot->poll = gp_active_layer_poll; | ot->poll = gp_active_layer_poll; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| ot->prop = RNA_def_enum(ot->srna, "type", slot_move, 0, "Type", ""); | ot->prop = RNA_def_enum(ot->srna, "type", slot_move, 0, "Type", ""); | ||||
| prop = RNA_def_boolean(ot->srna, "is_annotation", false, "Annotation", ""); | |||||
| RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); | |||||
| } | } | ||||
| void GPENCIL_OT_layer_annotation_move(wmOperatorType *ot) | |||||
| { | |||||
| PropertyRNA *prop; | |||||
| static const EnumPropertyItem slot_move[] = { | |||||
| {GP_LAYER_MOVE_UP, "UP", 0, "Up", ""}, | |||||
| {GP_LAYER_MOVE_DOWN, "DOWN", 0, "Down", ""}, | |||||
| {0, NULL, 0, NULL, NULL}, | |||||
| }; | |||||
| /* identifiers */ | |||||
| ot->name = "Move Annotation Layer"; | |||||
| ot->idname = "GPENCIL_OT_layer_annotation_move"; | |||||
| ot->description = "Move the active Annotation layer up/down in the list"; | |||||
| /* api callbacks */ | |||||
| ot->exec = gp_layer_move_exec; | |||||
| ot->poll = gp_active_layer_annotation_poll; | |||||
| /* flags */ | |||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | |||||
| ot->prop = RNA_def_enum(ot->srna, "type", slot_move, 0, "Type", ""); | |||||
| prop = RNA_def_boolean(ot->srna, "is_annotation", true, "Annotation", ""); | |||||
| RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); | |||||
| } | |||||
| /* ********************* Duplicate Layer ************************** */ | /* ********************* Duplicate Layer ************************** */ | ||||
| static int gp_layer_copy_exec(bContext *C, wmOperator *UNUSED(op)) | static int gp_layer_copy_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| bGPdata *gpd = ED_gpencil_data_get_active(C); | bGPdata *gpd = ED_gpencil_data_get_active(C); | ||||
| bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd); | bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd); | ||||
| bGPDlayer *new_layer; | bGPDlayer *new_layer; | ||||
| ▲ Show 20 Lines • Show All 585 Lines • ▼ Show 20 Lines | void GPENCIL_OT_lock_all(wmOperatorType *ot) | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Lock All Layers"; | ot->name = "Lock All Layers"; | ||||
| ot->idname = "GPENCIL_OT_lock_all"; | ot->idname = "GPENCIL_OT_lock_all"; | ||||
| ot->description = | ot->description = | ||||
| "Lock all Grease Pencil layers to prevent them from being accidentally modified"; | "Lock all Grease Pencil layers to prevent them from being accidentally modified"; | ||||
| /* callbacks */ | /* callbacks */ | ||||
| ot->exec = gp_lock_all_exec; | ot->exec = gp_lock_all_exec; | ||||
| ot->poll = gp_reveal_poll; /* XXX: could use dedicated poll later */ | ot->poll = gp_reveal_poll; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| } | } | ||||
| /* -------------------------- */ | /* -------------------------- */ | ||||
| static int gp_unlock_all_exec(bContext *C, wmOperator *UNUSED(op)) | static int gp_unlock_all_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| Show All 22 Lines | |||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Unlock All Layers"; | ot->name = "Unlock All Layers"; | ||||
| ot->idname = "GPENCIL_OT_unlock_all"; | ot->idname = "GPENCIL_OT_unlock_all"; | ||||
| ot->description = "Unlock all Grease Pencil layers so that they can be edited"; | ot->description = "Unlock all Grease Pencil layers so that they can be edited"; | ||||
| /* callbacks */ | /* callbacks */ | ||||
| ot->exec = gp_unlock_all_exec; | ot->exec = gp_unlock_all_exec; | ||||
| ot->poll = gp_reveal_poll; /* XXX: could use dedicated poll later */ | ot->poll = gp_reveal_poll; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| } | } | ||||
| /* ********************** Isolate Layer **************************** */ | /* ********************** Isolate Layer **************************** */ | ||||
| static int gp_isolate_layer_exec(bContext *C, wmOperator *op) | static int gp_isolate_layer_exec(bContext *C, wmOperator *op) | ||||
| ▲ Show 20 Lines • Show All 1,132 Lines • ▼ Show 20 Lines | if (fcu->driver) { | ||||
| for (DriverVar *dvar = fcu->driver->variables.first; dvar; dvar = dvar->next) { | for (DriverVar *dvar = fcu->driver->variables.first; dvar; dvar = dvar->next) { | ||||
| /* only change the used targets, since the others will need fixing manually anyway */ | /* only change the used targets, since the others will need fixing manually anyway */ | ||||
| DRIVER_TARGETS_USED_LOOPER_BEGIN (dvar) { | DRIVER_TARGETS_USED_LOOPER_BEGIN (dvar) { | ||||
| /* change the ID's used... */ | /* change the ID's used... */ | ||||
| if (dtar->id == src_id) { | if (dtar->id == src_id) { | ||||
| dtar->id = dst_id; | dtar->id = dst_id; | ||||
| /* also check on the subtarget... | /* also check on the subtarget... | ||||
| * XXX: We duplicate the logic from drivers_path_rename_fix() here, with our own | * We duplicate the logic from drivers_path_rename_fix() here, with our own | ||||
dfelintoUnsubmitted Not Done Inline ActionsSee other comments re: comments code-style dfelinto: See other comments re: comments code-style | |||||
| * little twists so that we know that it isn't going to clobber the wrong data | * little twists so that we know that it isn't going to clobber the wrong data | ||||
| */ | */ | ||||
| if (dtar->rna_path && strstr(dtar->rna_path, "layers[")) { | if (dtar->rna_path && strstr(dtar->rna_path, "layers[")) { | ||||
| GHASH_ITER (gh_iter, afd->names_map) { | GHASH_ITER (gh_iter, afd->names_map) { | ||||
| const char *old_name = BLI_ghashIterator_getKey(&gh_iter); | const char *old_name = BLI_ghashIterator_getKey(&gh_iter); | ||||
| const char *new_name = BLI_ghashIterator_getValue(&gh_iter); | const char *new_name = BLI_ghashIterator_getValue(&gh_iter); | ||||
| /* only remap if changed */ | /* only remap if changed */ | ||||
| if (!STREQ(old_name, new_name)) { | if (!STREQ(old_name, new_name)) { | ||||
| Show All 29 Lines | int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op) | ||||
| } | } | ||||
| bGPdata *gpd = (bGPdata *)ob_active->data; | bGPdata *gpd = (bGPdata *)ob_active->data; | ||||
| if ((!gpd) || GPENCIL_ANY_MODE(gpd)) { | if ((!gpd) || GPENCIL_ANY_MODE(gpd)) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| /* Ensure all rotations are applied before */ | /* Ensure all rotations are applied before */ | ||||
| // XXX: Why don't we apply them here instead of warning? | |||||
| CTX_DATA_BEGIN (C, Object *, ob_iter, selected_editable_objects) { | CTX_DATA_BEGIN (C, Object *, ob_iter, selected_editable_objects) { | ||||
| if (ob_iter->type == OB_GPENCIL) { | if (ob_iter->type == OB_GPENCIL) { | ||||
| if ((ob_iter->rot[0] != 0) || (ob_iter->rot[1] != 0) || (ob_iter->rot[2] != 0)) { | if ((ob_iter->rot[0] != 0) || (ob_iter->rot[1] != 0) || (ob_iter->rot[2] != 0)) { | ||||
| BKE_report(op->reports, RPT_ERROR, "Apply all rotations before join objects"); | BKE_report(op->reports, RPT_ERROR, "Apply all rotations before join objects"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 777 Lines • Show Last 20 Lines | |||||
See my comment about is_annotation elsewhere