Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_node/node_add.c
| Show First 20 Lines • Show All 439 Lines • ▼ Show 20 Lines | |||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Add Node Object Operator | /** \name Add Node Object Operator | ||||
| * \{ */ | * \{ */ | ||||
| static Object *node_add_object_get_and_poll_object_node_tree(Main *bmain, wmOperator *op) | static Object *node_add_object_get_and_poll_object_node_tree(Main *bmain, wmOperator *op) | ||||
| { | { | ||||
| char name[MAX_ID_NAME - 2]; | if (RNA_struct_property_is_set(op->ptr, "session_uuid")) { | ||||
| RNA_string_get(op->ptr, "name", name); | const uint32_t session_uuid = (uint32_t)RNA_int_get(op->ptr, "session_uuid"); | ||||
| return (Object *)BKE_libblock_find_session_uuid(bmain, ID_OB, session_uuid); | |||||
| Object *object = (Object *)BKE_libblock_find_name(bmain, ID_OB, name); | |||||
| if (!object) { | |||||
| return NULL; | |||||
| } | } | ||||
| return object; | char name[MAX_ID_NAME - 2]; | ||||
| RNA_string_get(op->ptr, "name", name); | |||||
| return (Object *)BKE_libblock_find_name(bmain, ID_OB, name); | |||||
| } | } | ||||
| static int node_add_object_exec(bContext *C, wmOperator *op) | static int node_add_object_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| SpaceNode *snode = CTX_wm_space_node(C); | SpaceNode *snode = CTX_wm_space_node(C); | ||||
| bNodeTree *ntree = snode->edittree; | bNodeTree *ntree = snode->edittree; | ||||
| Object *object; | Object *object; | ||||
| ▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | void NODE_OT_add_object(wmOperatorType *ot) | ||||
| ot->exec = node_add_object_exec; | ot->exec = node_add_object_exec; | ||||
| ot->invoke = node_add_object_invoke; | ot->invoke = node_add_object_invoke; | ||||
| ot->poll = node_add_object_poll; | ot->poll = node_add_object_poll; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; | ||||
| RNA_def_string(ot->srna, "name", "Object", MAX_ID_NAME - 2, "Name", "Data-block name to assign"); | RNA_def_string(ot->srna, "name", "Object", MAX_ID_NAME - 2, "Name", "Data-block name to assign"); | ||||
| RNA_def_int(ot->srna, | |||||
| "session_uuid", | |||||
| 0, | |||||
| INT32_MIN, | |||||
| INT32_MAX, | |||||
| "Session UUID", | |||||
| "Session UUID of the data-block to assign", | |||||
| INT32_MIN, | |||||
| INT32_MAX); | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Add Node Texture Operator | /** \name Add Node Texture Operator | ||||
| * \{ */ | * \{ */ | ||||
| static Tex *node_add_texture_get_and_poll_texture_node_tree(Main *bmain, wmOperator *op) | static Tex *node_add_texture_get_and_poll_texture_node_tree(Main *bmain, wmOperator *op) | ||||
| { | { | ||||
| char name[MAX_ID_NAME - 2]; | if (RNA_struct_property_is_set(op->ptr, "session_uuid")) { | ||||
| RNA_string_get(op->ptr, "name", name); | const uint32_t session_uuid = (uint32_t)RNA_int_get(op->ptr, "session_uuid"); | ||||
| return (Tex *)BKE_libblock_find_session_uuid(bmain, ID_TE, session_uuid); | |||||
| Tex *texture = (Tex *)BKE_libblock_find_name(bmain, ID_TE, name); | |||||
| if (!texture) { | |||||
| return NULL; | |||||
| } | } | ||||
| return texture; | char name[MAX_ID_NAME - 2]; | ||||
| RNA_string_get(op->ptr, "name", name); | |||||
| return (Tex *)BKE_libblock_find_name(bmain, ID_TE, name); | |||||
| } | } | ||||
| static int node_add_texture_exec(bContext *C, wmOperator *op) | static int node_add_texture_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| SpaceNode *snode = CTX_wm_space_node(C); | SpaceNode *snode = CTX_wm_space_node(C); | ||||
| bNodeTree *ntree = snode->edittree; | bNodeTree *ntree = snode->edittree; | ||||
| Tex *texture; | Tex *texture; | ||||
| ▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | void NODE_OT_add_texture(wmOperatorType *ot) | ||||
| ot->invoke = node_add_texture_invoke; | ot->invoke = node_add_texture_invoke; | ||||
| ot->poll = node_add_texture_poll; | ot->poll = node_add_texture_poll; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; | ||||
| RNA_def_string( | RNA_def_string( | ||||
| ot->srna, "name", "Texture", MAX_ID_NAME - 2, "Name", "Data-block name to assign"); | ot->srna, "name", "Texture", MAX_ID_NAME - 2, "Name", "Data-block name to assign"); | ||||
| RNA_def_int(ot->srna, | |||||
| "session_uuid", | |||||
| 0, | |||||
| INT32_MIN, | |||||
| INT32_MAX, | |||||
| "Session UUID", | |||||
| "Session UUID of the data-block to assign", | |||||
| INT32_MIN, | |||||
| INT32_MAX); | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Add Node Collection Operator | /** \name Add Node Collection Operator | ||||
| * \{ */ | * \{ */ | ||||
| static Collection *node_add_collection_get_and_poll_collection_node_tree(Main *bmain, | static Collection *node_add_collection_get_and_poll_collection_node_tree(Main *bmain, | ||||
| wmOperator *op) | wmOperator *op) | ||||
| { | { | ||||
| char name[MAX_ID_NAME - 2]; | if (RNA_struct_property_is_set(op->ptr, "session_uuid")) { | ||||
| RNA_string_get(op->ptr, "name", name); | const uint32_t session_uuid = (uint32_t)RNA_int_get(op->ptr, "session_uuid"); | ||||
| return (Collection *)BKE_libblock_find_session_uuid(bmain, ID_GR, session_uuid); | |||||
| Collection *collection = (Collection *)BKE_libblock_find_name(bmain, ID_GR, name); | |||||
| if (!collection) { | |||||
| return NULL; | |||||
| } | } | ||||
| return collection; | char name[MAX_ID_NAME - 2]; | ||||
| RNA_string_get(op->ptr, "name", name); | |||||
| return (Collection *)BKE_libblock_find_name(bmain, ID_GR, name); | |||||
| } | } | ||||
| static int node_add_collection_exec(bContext *C, wmOperator *op) | static int node_add_collection_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| SpaceNode *snode = CTX_wm_space_node(C); | SpaceNode *snode = CTX_wm_space_node(C); | ||||
| bNodeTree *ntree = snode->edittree; | bNodeTree *ntree = snode->edittree; | ||||
| Collection *collection; | Collection *collection; | ||||
| ▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | void NODE_OT_add_collection(wmOperatorType *ot) | ||||
| ot->invoke = node_add_collection_invoke; | ot->invoke = node_add_collection_invoke; | ||||
| ot->poll = node_add_collection_poll; | ot->poll = node_add_collection_poll; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; | ||||
| RNA_def_string( | RNA_def_string( | ||||
| ot->srna, "name", "Collection", MAX_ID_NAME - 2, "Name", "Data-block name to assign"); | ot->srna, "name", "Collection", MAX_ID_NAME - 2, "Name", "Data-block name to assign"); | ||||
| RNA_def_int(ot->srna, | |||||
| "session_uuid", | |||||
| 0, | |||||
| INT32_MIN, | |||||
| INT32_MAX, | |||||
| "Session UUID", | |||||
| "Session UUID of the data-block to assign", | |||||
| INT32_MIN, | |||||
| INT32_MAX); | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Add File Node Operator | /** \name Add File Node Operator | ||||
| * \{ */ | * \{ */ | ||||
| ▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Add Mask Node Operator | /** \name Add Mask Node Operator | ||||
| * \{ */ | * \{ */ | ||||
| static ID *node_add_mask_get_and_poll_mask(Main *bmain, wmOperator *op) | |||||
| { | |||||
| if (RNA_struct_property_is_set(op->ptr, "session_uuid")) { | |||||
| const uint32_t session_uuid = (uint32_t)RNA_int_get(op->ptr, "session_uuid"); | |||||
| return BKE_libblock_find_session_uuid(bmain, ID_MSK, session_uuid); | |||||
| } | |||||
| char name[MAX_ID_NAME - 2]; | |||||
| RNA_string_get(op->ptr, "name", name); | |||||
| return BKE_libblock_find_name(bmain, ID_MSK, name); | |||||
| } | |||||
| static bool node_add_mask_poll(bContext *C) | static bool node_add_mask_poll(bContext *C) | ||||
| { | { | ||||
| SpaceNode *snode = CTX_wm_space_node(C); | SpaceNode *snode = CTX_wm_space_node(C); | ||||
| return ED_operator_node_editable(C) && snode->nodetree->type == NTREE_COMPOSIT; | return ED_operator_node_editable(C) && snode->nodetree->type == NTREE_COMPOSIT; | ||||
| } | } | ||||
| static int node_add_mask_exec(bContext *C, wmOperator *op) | static int node_add_mask_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| SpaceNode *snode = CTX_wm_space_node(C); | SpaceNode *snode = CTX_wm_space_node(C); | ||||
| bNode *node; | bNode *node; | ||||
| ID *mask = NULL; | |||||
| /* check input variables */ | ID *mask = node_add_mask_get_and_poll_mask(bmain, op); | ||||
| char name[MAX_ID_NAME - 2]; | |||||
| RNA_string_get(op->ptr, "name", name); | |||||
| mask = BKE_libblock_find_name(bmain, ID_MSK, name); | |||||
| if (!mask) { | if (!mask) { | ||||
| BKE_reportf(op->reports, RPT_ERROR, "Mask '%s' not found", name); | |||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); | ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); | ||||
| node = node_add_node( | node = node_add_node( | ||||
| C, NULL, CMP_NODE_MASK, snode->runtime->cursor[0], snode->runtime->cursor[1]); | C, NULL, CMP_NODE_MASK, snode->runtime->cursor[0], snode->runtime->cursor[1]); | ||||
| Show All 21 Lines | void NODE_OT_add_mask(wmOperatorType *ot) | ||||
| /* callbacks */ | /* callbacks */ | ||||
| ot->exec = node_add_mask_exec; | ot->exec = node_add_mask_exec; | ||||
| ot->poll = node_add_mask_poll; | ot->poll = node_add_mask_poll; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; | ||||
| RNA_def_string(ot->srna, "name", "Mask", MAX_ID_NAME - 2, "Name", "Data-block name to assign"); | RNA_def_string(ot->srna, "name", "Mask", MAX_ID_NAME - 2, "Name", "Data-block name to assign"); | ||||
| RNA_def_int(ot->srna, | |||||
| "session_uuid", | |||||
| 0, | |||||
| INT32_MIN, | |||||
| INT32_MAX, | |||||
| "Session UUID", | |||||
| "Session UUID of the data-block to assign", | |||||
| INT32_MIN, | |||||
| INT32_MAX); | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name New Node Tree Operator | /** \name New Node Tree Operator | ||||
| * \{ */ | * \{ */ | ||||
| ▲ Show 20 Lines • Show All 88 Lines • Show Last 20 Lines | |||||