Пример #1
0
static int node_group_insert_exec(bContext *C, wmOperator *op)
{
	SpaceNode *snode = CTX_wm_space_node(C);
	bNodeTree *ntree = snode->edittree;
	bNodeTree *ngroup;
	const char *node_idname = group_node_idname(C);
	bNode *gnode;
	Main *bmain = CTX_data_main(C);
	
	ED_preview_kill_jobs(C);
	
	gnode = node_group_get_active(C, node_idname);
	
	if (!gnode || !gnode->id)
		return OPERATOR_CANCELLED;
	
	ngroup = (bNodeTree *)gnode->id;
	if (!node_group_make_test_selected(ntree, gnode, ngroup->idname, op->reports))
		return OPERATOR_CANCELLED;
	
	node_group_make_insert_selected(C, ntree, gnode);
	
	nodeSetActive(ntree, gnode);
	ED_node_tree_push(snode, ngroup, gnode);
	ntreeUpdateTree(bmain, ngroup);
	
	ntreeUpdateTree(bmain, ntree);
	
	snode_notify(C, snode);
	snode_dag_update(C, snode);
	
	return OPERATOR_FINISHED;
}
Пример #2
0
/* active node */
static void active_node_panel(const bContext *C, Panel *pa)
{
	SpaceNode *snode= CTX_wm_space_node(C);
	bNodeTree *ntree= (snode) ? snode->edittree : NULL;
	bNode *node = (ntree) ? nodeGetActive(ntree) : NULL; // xxx... for editing group nodes
	uiLayout *layout= pa->layout;
	uiBlock *block;
	PointerRNA ptr;
	
	/* verify pointers, and create RNA pointer for the node */
	if ELEM(NULL, ntree, node)
		return;
	//if (node->id) /* for group nodes */
	//	RNA_pointer_create(node->id, &RNA_Node, node, &ptr);
	//else
		RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr); 
	
	/* set update callback */
	// xxx is this really needed
	block= uiLayoutGetBlock(layout);
	uiBlockSetHandleFunc(block, do_node_region_buttons, NULL);
	
	/* draw this node's name, etc. */
	uiItemR(layout, &ptr, "label", 0, NULL, ICON_NODE);
	uiItemS(layout);
	uiItemR(layout, &ptr, "name", 0, NULL, ICON_NODE);
	uiItemS(layout);

	/* draw this node's settings */
	if (node->typeinfo && node->typeinfo->uifuncbut)
		node->typeinfo->uifuncbut(layout, (bContext *)C, &ptr);
	else if (node->typeinfo && node->typeinfo->uifunc)
		node->typeinfo->uifunc(layout, (bContext *)C, &ptr);
}
Пример #3
0
static void do_node_add_group(bContext *C, void *UNUSED(arg), int event)
{
	SpaceNode *snode = CTX_wm_space_node(C);
	Main *bmain = CTX_data_main(C);
	Scene *scene = CTX_data_scene(C);
	bNodeTemplate ntemp;
	
	if (event >= 0) {
		ntemp.ngroup = BLI_findlink(&G.main->nodetree, event);
		ntemp.type = ntemp.ngroup->nodetype;
	}
	else {
		ntemp.type = -event;
		switch (ntemp.type) {
			case NODE_GROUP:
				ntemp.ngroup = ntreeAddTree("Group", snode->treetype, ntemp.type);
				break;
			default:
				ntemp.ngroup = NULL;
		}
	}
	if (!ntemp.ngroup)
		return;
	
	ntemp.main = bmain;
	ntemp.scene = scene;
	
	do_node_add(C, &ntemp);
}
Пример #4
0
/* poll callback for active node */
static int active_node_poll(const bContext *C, PanelType *UNUSED(pt))
{
	SpaceNode *snode= CTX_wm_space_node(C);
	
	// TODO: include check for whether there is an active node...
	return (snode && snode->nodetree);
}
Пример #5
0
static int snode_bg_viewmove_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
    SpaceNode *snode = CTX_wm_space_node(C);
    ARegion *ar = CTX_wm_region(C);
    NodeViewMove *nvm = op->customdata;

    switch (event->type) {
    case MOUSEMOVE:

        snode->xof -= (nvm->mvalo[0] - event->mval[0]);
        snode->yof -= (nvm->mvalo[1] - event->mval[1]);
        nvm->mvalo[0] = event->mval[0];
        nvm->mvalo[1] = event->mval[1];

        /* prevent dragging image outside of the window and losing it! */
        CLAMP(snode->xof, nvm->xmin, nvm->xmax);
        CLAMP(snode->yof, nvm->ymin, nvm->ymax);

        ED_region_tag_redraw(ar);
        WM_main_add_notifier(NC_NODE | ND_DISPLAY, NULL);

        break;

    case LEFTMOUSE:
    case MIDDLEMOUSE:
    case RIGHTMOUSE:

        MEM_freeN(nvm);
        op->customdata = NULL;

        return OPERATOR_FINISHED;
    }

    return OPERATOR_RUNNING_MODAL;
}
Пример #6
0
static int node_select_exec(bContext *C, wmOperator *op)
{
	Main *bmain = CTX_data_main(C);
	SpaceNode *snode = CTX_wm_space_node(C);
	ARegion *ar = CTX_wm_region(C);
	int mval[2];
	short extend;
	
	/* get settings from RNA properties for operator */
	mval[0] = RNA_int_get(op->ptr, "mouse_x");
	mval[1] = RNA_int_get(op->ptr, "mouse_y");
	
	extend = RNA_boolean_get(op->ptr, "extend");
	
	/* perform the select */
	if (node_mouse_select(bmain, snode, ar, mval, extend)) {
		/* send notifiers */
		WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL);
		
		/* allow tweak event to work too */
		return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH;
	}
	else {
		/* allow tweak event to work too */
		return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH;
	}
}
Пример #7
0
static int node_circleselect_exec(bContext *C, wmOperator *op)
{
	SpaceNode *snode = CTX_wm_space_node(C);
	ARegion *ar = CTX_wm_region(C);
	bNode *node;

	int x, y, radius, gesture_mode;
	float offset[2];

	float zoom  = (float)(BLI_rcti_size_x(&ar->winrct)) / (float)(BLI_rctf_size_x(&ar->v2d.cur));

	gesture_mode = RNA_int_get(op->ptr, "gesture_mode");

	/* get operator properties */
	x = RNA_int_get(op->ptr, "x");
	y = RNA_int_get(op->ptr, "y");
	radius = RNA_int_get(op->ptr, "radius");

	UI_view2d_region_to_view(&ar->v2d, x, y, &offset[0], &offset[1]);

	for (node = snode->edittree->nodes.first; node; node = node->next) {
		if (BLI_rctf_isect_circle(&node->totr, offset, radius / zoom)) {
			nodeSetSelected(node, (gesture_mode == GESTURE_MODAL_SELECT));
		}
	}

	WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL);

	return OPERATOR_FINISHED;
}
Пример #8
0
static int node_borderselect_exec(bContext *C, wmOperator *op)
{
	SpaceNode *snode = CTX_wm_space_node(C);
	ARegion *ar = CTX_wm_region(C);
	bNode *node;
	rctf rectf;
	int gesture_mode = RNA_int_get(op->ptr, "gesture_mode");
	const bool extend = RNA_boolean_get(op->ptr, "extend");
	
	WM_operator_properties_border_to_rctf(op, &rectf);
	UI_view2d_region_to_view_rctf(&ar->v2d, &rectf, &rectf);
	
	for (node = snode->edittree->nodes.first; node; node = node->next) {
		if (BLI_rctf_isect(&rectf, &node->totr, NULL)) {
			nodeSetSelected(node, (gesture_mode == GESTURE_MODAL_SELECT));
		}
		else if (!extend) {
			nodeSetSelected(node, false);
		}
	}
	
	ED_node_sort(snode->edittree);
	
	WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL);

	return OPERATOR_FINISHED;
}
Пример #9
0
static bool do_lasso_select_node(bContext *C, const int mcords[][2], short moves, short select)
{
	SpaceNode *snode = CTX_wm_space_node(C);
	bNode *node;

	ARegion *ar = CTX_wm_region(C);

	rcti rect;
	bool changed = false;

	/* get rectangle from operator */
	BLI_lasso_boundbox(&rect, mcords, moves);

	/* do actual selection */
	for (node = snode->edittree->nodes.first; node; node = node->next) {
		int screen_co[2];
		const float cent[2] = {BLI_rctf_cent_x(&node->totr),
		                       BLI_rctf_cent_y(&node->totr)};

		/* marker in screen coords */
		if (UI_view2d_view_to_region_clip(&ar->v2d, cent[0], cent[1], &screen_co[0], &screen_co[1]) &&
		    BLI_rcti_isect_pt(&rect, screen_co[0], screen_co[1]) &&
		    BLI_lasso_is_point_inside(mcords, moves, screen_co[0], screen_co[1], INT_MAX))
		{
			nodeSetSelected(node, select);
			changed = true;
		}
	}

	if (changed) {
		WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL);
	}

	return changed;
}
Пример #10
0
static int node_select_linked_from_exec(bContext *C, wmOperator *UNUSED(op))
{
	SpaceNode *snode = CTX_wm_space_node(C);
	bNodeLink *link;
	bNode *node;
	
	for (node = snode->edittree->nodes.first; node; node = node->next)
		node->flag &= ~NODE_TEST;

	for (link = snode->edittree->links.first; link; link = link->next) {
		if (nodeLinkIsHidden(link))
			continue;
		if (link->fromnode && link->tonode && (link->tonode->flag & NODE_SELECT))
			link->fromnode->flag |= NODE_TEST;
	}
	
	for (node = snode->edittree->nodes.first; node; node = node->next) {
		if (node->flag & NODE_TEST)
			nodeSetSelected(node, true);
	}
	
	ED_node_sort(snode->edittree);
	
	WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL);
	return OPERATOR_FINISHED;
}
Пример #11
0
static int node_select_all_exec(bContext *C, wmOperator *op)
{
	SpaceNode *snode = CTX_wm_space_node(C);
	ListBase *node_lb = &snode->edittree->nodes;
	bNode *node;
	int action = RNA_enum_get(op->ptr, "action");

	if (action == SEL_TOGGLE) {
		if (ED_node_select_check(node_lb))
			action = SEL_DESELECT;
		else
			action = SEL_SELECT;
	}

	for (node = node_lb->first; node; node = node->next) {
		switch (action) {
			case SEL_SELECT:
				nodeSetSelected(node, true);
				break;
			case SEL_DESELECT:
				nodeSetSelected(node, false);
				break;
			case SEL_INVERT:
				nodeSetSelected(node, !(node->flag & SELECT));
				break;
		}
	}

	ED_node_sort(snode->edittree);
	
	WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL);
	return OPERATOR_FINISHED;
}
Пример #12
0
static void do_node_add_group(bContext *C, void *UNUSED(arg), int event)
{
	SpaceNode *snode= CTX_wm_space_node(C);
	bNodeTemplate ntemp;
	
	if (event>=0) {
		ntemp.ngroup= BLI_findlink(&G.main->nodetree, event);
		ntemp.type = ntemp.ngroup->nodetype;
	}
	else {
		ntemp.type = -event;
		switch (ntemp.type) {
		case NODE_GROUP:
			ntemp.ngroup = ntreeAddTree("Group", snode->treetype, ntemp.type);
			break;
		case NODE_FORLOOP:
			ntemp.ngroup = ntreeAddTree("For Loop", snode->treetype, ntemp.type);
			break;
		case NODE_WHILELOOP:
			ntemp.ngroup = ntreeAddTree("While Loop", snode->treetype, ntemp.type);
			break;
		default:
			ntemp.ngroup = NULL;
		}
	}
	if (!ntemp.ngroup)
		return;
	
	do_node_add(C, &ntemp);
}
Пример #13
0
static int node_group_ungroup_exec(bContext *C, wmOperator *op)
{
	SpaceNode *snode = CTX_wm_space_node(C);
	const char *node_idname = group_node_idname(C);
	bNode *gnode;

	ED_preview_kill_jobs(C);

	gnode = node_group_get_active(C, node_idname);
	if (!gnode)
		return OPERATOR_CANCELLED;
	
	if (gnode->id && node_group_ungroup(snode->edittree, gnode)) {
		ntreeUpdateTree(CTX_data_main(C), snode->nodetree);
	}
	else {
		BKE_report(op->reports, RPT_WARNING, "Cannot ungroup");
		return OPERATOR_CANCELLED;
	}

	snode_notify(C, snode);
	snode_dag_update(C, snode);

	return OPERATOR_FINISHED;
}
Пример #14
0
static void shader_get_from_context(const bContext *C, bNodeTreeType *UNUSED(treetype), bNodeTree **r_ntree, ID **r_id, ID **r_from)
{
	SpaceNode *snode = CTX_wm_space_node(C);
	Scene *scene = CTX_data_scene(C);
	Object *ob = OBACT;
	
	if (!BKE_scene_use_new_shading_nodes(scene) || snode->shaderfrom == SNODE_SHADER_OBJECT) {
		if (ob) {
			*r_from = &ob->id;
			if (ob->type == OB_LAMP) {
				*r_id = ob->data;
				*r_ntree = ((Lamp *)ob->data)->nodetree;
			}
			else {
				Material *ma = give_current_material(ob, ob->actcol);
				if (ma) {
					*r_id = &ma->id;
					*r_ntree = ma->nodetree;
				}
			}
		}
	}
	else { /* SNODE_SHADER_WORLD */
		if (scene->world) {
			*r_from = NULL;
			*r_id = &scene->world->id;
			*r_ntree = scene->world->nodetree;
		}
	}
}
Пример #15
0
static void do_node_internal_buttons(bContext *C, void *node_v, int event)
{
	if(event==B_NODE_EXEC) {
		SpaceNode *snode= CTX_wm_space_node(C);
		if(snode && snode->id)
			ED_node_changed_update(snode->id, node_v);
	}
}
Пример #16
0
static bNode *node_group_get_active(bContext *C, const char *node_idname)
{
	SpaceNode *snode = CTX_wm_space_node(C);
	bNode *node = nodeGetActive(snode->edittree);
	
	if (node && STREQ(node->idname, node_idname))
		return node;
	else
		return NULL;
}
Пример #17
0
static int node_view_all_exec(bContext *C, wmOperator *UNUSED(op))
{
	ScrArea *sa= CTX_wm_area(C);
	ARegion *ar= CTX_wm_region(C);
	SpaceNode *snode= CTX_wm_space_node(C);
	
	snode_home(sa, ar, snode);
	ED_region_tag_redraw(ar);
	
	return OPERATOR_FINISHED;
}
Пример #18
0
static int node_select_same_type_exec(bContext *C, wmOperator *UNUSED(op))
{
	SpaceNode *snode = CTX_wm_space_node(C);

	node_select_same_type(snode);

	ED_node_sort(snode->edittree);

	WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL);
	return OPERATOR_FINISHED;
}
Пример #19
0
static void node_add_menu(bContext *C, uiLayout *layout, void *arg_nodeclass)
{
	Main *bmain = CTX_data_main(C);
	Scene *scene = CTX_data_scene(C);
	SpaceNode *snode = CTX_wm_space_node(C);
	bNodeTree *ntree;
	int nodeclass = GET_INT_FROM_POINTER(arg_nodeclass);
	int event, compatibility = 0;
	
	ntree = snode->nodetree;
	
	if (!ntree) {
		uiItemS(layout);
		return;
	}

	if (ntree->type == NTREE_SHADER) {
		if (BKE_scene_use_new_shading_nodes(scene))
			compatibility = NODE_NEW_SHADING;
		else
			compatibility = NODE_OLD_SHADING;
	}
	
	if (nodeclass == NODE_CLASS_GROUP) {
		bNodeTree *ngroup;
		
		uiLayoutSetFunc(layout, do_node_add_group, NULL);
		
		/* XXX hack: negative numbers used for empty group types */
		if (node_tree_has_type(ntree->type, NODE_GROUP))
			uiItemV(layout, IFACE_("New Group"), 0, -NODE_GROUP);
		uiItemS(layout);
		
		for (ngroup = bmain->nodetree.first, event = 0; ngroup; ngroup = ngroup->id.next, ++event) {
			/* only use group trees */
			if (ngroup->type == ntree->type && ngroup->nodetype == NODE_GROUP) {
				uiItemV(layout, ngroup->id.name + 2, 0, event);
			}
		}
	}
	else {
		bNodeType *ntype;
		
		uiLayoutSetFunc(layout, do_node_add_static, NULL);
		
		for (ntype = ntreeGetType(ntree->type)->node_types.first; ntype; ntype = ntype->next) {
			if (ntype->nclass == nodeclass && ntype->name) {
				if (!compatibility || (ntype->compatibility & compatibility)) {
					uiItemV(layout, IFACE_(ntype->name), 0, ntype->type);
				}
			}
		}
	}
}
Пример #20
0
static void node_menu_add(const bContext *C, Menu *menu)
{
	SpaceNode *snode= CTX_wm_space_node(C);
	uiLayout *layout= menu->layout;

	if(!snode->nodetree)
		uiLayoutSetActive(layout, 0);

	if(snode->treetype==NTREE_SHADER) {
		uiItemMenuF(layout, IFACE_(N_("Input")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_INPUT));
		uiItemMenuF(layout, IFACE_(N_("Output")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OUTPUT));
		uiItemMenuF(layout, IFACE_(N_("Color")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OP_COLOR));
		uiItemMenuF(layout, IFACE_(N_("Vector")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OP_VECTOR));
		uiItemMenuF(layout, IFACE_(N_("Convertor")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_CONVERTOR));
		uiItemMenuF(layout, IFACE_(N_("Group")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_GROUP));
		uiItemMenuF(layout, IFACE_(N_("Dynamic")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OP_DYNAMIC));
		uiItemMenuF(layout, IFACE_(N_("Layout")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_LAYOUT));
	}
	else if(snode->treetype==NTREE_COMPOSIT) {
		uiItemMenuF(layout, IFACE_(N_("Input")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_INPUT));
		uiItemMenuF(layout, IFACE_(N_("Output")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OUTPUT));
		
                uiItemMenuF(layout, "OpenCV Input", 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OCV_INPUT));
                uiItemMenuF(layout, "OpenCV Output", 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OCV_OUTPUT));
                uiItemMenuF(layout, "Array operations", 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OCV_ARRAY));
                uiItemMenuF(layout, "Drawing functions", 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OCV_DRAW));
                uiItemMenuF(layout, "Data persistent", 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OCV_DATAPERSIST));
                uiItemMenuF(layout, "Miscelllaneous", 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OCV_MISC));
                uiItemMenuF(layout, "Image processing", 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OCV_IMAGEPROCESS));
                uiItemMenuF(layout, "Structural analysis", 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OCV_STRUCTANALYSIS));
                uiItemMenuF(layout, "Motion analysis and object tracking", 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OCV_MOTIONANALYSIS));
                uiItemMenuF(layout, "Pattern recognition", 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OCV_PATTERNRECOGNITION));
                uiItemMenuF(layout, "Camera calibration and 3D reconstruction", 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OCV_CAMERACALIBRATION));
                uiItemMenuF(layout, "Machine learning", 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OCV_MACHINELEARNING));
                
                uiItemMenuF(layout, IFACE_(N_("Group")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_GROUP));
		uiItemMenuF(layout, IFACE_(N_("Layout")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_LAYOUT));
                //uiItemMenuF(layout, "OpenCV", 0, node_add_sub_menu_opencv, SET_INT_IN_POINTER(NODE_CLASS_OPENCV));
                uiItemMenuF(layout, "OpenCV", 0, node_add_sub_menu_blender, SET_INT_IN_POINTER(NODE_CLASS_BLENDERSUB));
                
	}
	else if(snode->treetype==NTREE_TEXTURE) {
		uiItemMenuF(layout, IFACE_(N_("Input")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_INPUT));
		uiItemMenuF(layout, IFACE_(N_("Output")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OUTPUT));
		uiItemMenuF(layout, IFACE_(N_("Color")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OP_COLOR));
		uiItemMenuF(layout, IFACE_(N_("Patterns")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_PATTERN));
		uiItemMenuF(layout, IFACE_(N_("Textures")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_TEXTURE));
		uiItemMenuF(layout, IFACE_(N_("Convertor")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_CONVERTOR));
		uiItemMenuF(layout, IFACE_(N_("Distort")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_DISTORT));
		uiItemMenuF(layout, IFACE_(N_("Group")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_GROUP));
		uiItemMenuF(layout, IFACE_(N_("Layout")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_LAYOUT));
	}
}
Пример #21
0
static int backimage_zoom_exec(bContext *C, wmOperator *op)
{
    SpaceNode *snode = CTX_wm_space_node(C);
    ARegion *ar = CTX_wm_region(C);
    float fac = RNA_float_get(op->ptr, "factor");

    snode->zoom *= fac;
    ED_region_tag_redraw(ar);
    WM_main_add_notifier(NC_NODE | ND_DISPLAY, NULL);

    return OPERATOR_FINISHED;
}
Пример #22
0
static const char *group_node_idname(bContext *C)
{
	SpaceNode *snode = CTX_wm_space_node(C);
	
	if (STREQ(snode->tree_idname, "ShaderNodeTree"))
		return "ShaderNodeGroup";
	else if (STREQ(snode->tree_idname, "CompositorNodeTree"))
		return "CompositorNodeGroup";
	else if (STREQ(snode->tree_idname, "TextureNodeTree"))
		return "TextureNodeGroup";
	
	return "";
}
Пример #23
0
static int node_toggle_visibility_exec(bContext *C, wmOperator *op)
{
	SpaceNode *snode= CTX_wm_space_node(C);
	ARegion *ar= CTX_wm_region(C);
	int mval[2];

	mval[0] = RNA_int_get(op->ptr, "mouse_x");
	mval[1] = RNA_int_get(op->ptr, "mouse_y");
	if(node_toggle_visibility(snode, ar, mval))
		return OPERATOR_FINISHED;
	else
		return OPERATOR_CANCELLED|OPERATOR_PASS_THROUGH;
}
Пример #24
0
static int node_view_selected_exec(bContext *C, wmOperator *op)
{
    ARegion *ar = CTX_wm_region(C);
    SpaceNode *snode = CTX_wm_space_node(C);
    const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);

    if (space_node_view_flag(C, snode, ar, NODE_SELECT, smooth_viewtx)) {
        return OPERATOR_FINISHED;
    }
    else {
        return OPERATOR_CANCELLED;
    }
}
Пример #25
0
static void node_tree_interface_panel(const bContext *C, Panel *pa)
{
	SpaceNode *snode = CTX_wm_space_node(C);
	bNodeTree *ntree = (snode) ? snode->edittree : NULL;
	bNodeSocket *sock;
	int in_out;
	uiLayout *layout = pa->layout, *row, *split, *col;
	PointerRNA ptr, sockptr, opptr;

	if (!ntree)
		return;
	
	RNA_id_pointer_create((ID *)ntree, &ptr);
	
	node_tree_find_active_socket(ntree, &sock, &in_out);
	RNA_pointer_create((ID *)ntree, &RNA_NodeSocketInterface, sock, &sockptr);
	
	row = uiLayoutRow(layout, false);
	
	split = uiLayoutRow(row, true);
	col = uiLayoutColumn(split, true);
	uiItemL(col, IFACE_("Inputs:"), ICON_NONE);
	uiTemplateList(col, (bContext *)C, "NODE_UL_interface_sockets", "inputs", &ptr, "inputs", &ptr, "active_input",
	               NULL, 0, 0, 0, 0);
	opptr = uiItemFullO(col, "NODE_OT_tree_socket_add", "", ICON_PLUS, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
	RNA_enum_set(&opptr, "in_out", SOCK_IN);
	
	col = uiLayoutColumn(split, true);
	uiItemL(col, IFACE_("Outputs:"), ICON_NONE);
	uiTemplateList(col, (bContext *)C, "NODE_UL_interface_sockets", "outputs", &ptr, "outputs", &ptr, "active_output",
	               NULL, 0, 0, 0, 0);
	opptr = uiItemFullO(col, "NODE_OT_tree_socket_add", "", ICON_PLUS, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
	RNA_enum_set(&opptr, "in_out", SOCK_OUT);
	
	col = uiLayoutColumn(row, true);
	opptr = uiItemFullO(col, "NODE_OT_tree_socket_move", "", ICON_TRIA_UP, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
	RNA_enum_set(&opptr, "direction", 1);
	opptr = uiItemFullO(col, "NODE_OT_tree_socket_move", "", ICON_TRIA_DOWN, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
	RNA_enum_set(&opptr, "direction", 2);
	
	if (sock) {
		row = uiLayoutRow(layout, true);
		uiItemR(row, &sockptr, "name", 0, NULL, ICON_NONE);
		uiItemO(row, "", ICON_X, "NODE_OT_tree_socket_remove");
		
		if (sock->typeinfo->interface_draw) {
			uiItemS(layout);
			sock->typeinfo->interface_draw((bContext *)C, layout, &sockptr);
		}
	}
}
Пример #26
0
static void node_add_menu(bContext *C, uiLayout *layout, void *arg_nodeclass)
{
	Main *bmain= CTX_data_main(C);
	SpaceNode *snode= CTX_wm_space_node(C);
	bNodeTree *ntree;
	int nodeclass= GET_INT_FROM_POINTER(arg_nodeclass);
	int event;
	
	ntree = snode->nodetree;
	
	if(!ntree) {
		uiItemS(layout);
		return;
	}
	
	if (nodeclass==NODE_CLASS_GROUP) {
		bNodeTree *ngroup;
		
		uiLayoutSetFunc(layout, do_node_add_group, NULL);
		
		/* XXX hack: negative numbers used for empty group types */
		if (node_tree_has_type(ntree->type, NODE_GROUP))
			uiItemV(layout, "New Group", 0, -NODE_GROUP);
		if (node_tree_has_type(ntree->type, NODE_FORLOOP))
			uiItemV(layout, "New For Loop", 0, -NODE_FORLOOP);
		if (node_tree_has_type(ntree->type, NODE_WHILELOOP))
			uiItemV(layout, "New While Loop", 0, -NODE_WHILELOOP);
		uiItemS(layout);
		
		for(ngroup=bmain->nodetree.first, event=0; ngroup; ngroup= ngroup->id.next, ++event) {
			/* only use group trees */
			if (ngroup->type==ntree->type && ELEM3(ngroup->nodetype, NODE_GROUP, NODE_FORLOOP, NODE_WHILELOOP)) {
				uiItemV(layout, ngroup->id.name+2, 0, event);
			}
		}
	}
	else if (nodeclass==NODE_DYNAMIC) {
		/* disabled */
	}
	else {
		bNodeType *ntype;
		
		uiLayoutSetFunc(layout, do_node_add_static, NULL);
		
		for (ntype=ntreeGetType(ntree->type)->node_types.first; ntype; ntype=ntype->next) {
			if(ntype->nclass==nodeclass && ntype->name)
				uiItemV(layout, ntype->name, 0, ntype->type);
		}
	}
}
Пример #27
0
static void do_node_add(bContext *C, bNodeTemplate *ntemp)
{
	Main *bmain = CTX_data_main(C);
	Scene *scene = CTX_data_scene(C);
	SpaceNode *snode = CTX_wm_space_node(C);
	ScrArea *sa = CTX_wm_area(C);
	ARegion *ar;
	bNode *node, *node_new;
	
	/* get location to add node at mouse */
	for (ar = sa->regionbase.first; ar; ar = ar->next) {
		if (ar->regiontype == RGN_TYPE_WINDOW) {
			wmWindow *win = CTX_wm_window(C);
			int x = win->eventstate->x - ar->winrct.xmin;
			int y = win->eventstate->y - ar->winrct.ymin;
			
			if (y < 60) y += 60;
			UI_view2d_region_to_view(&ar->v2d, x, y, &snode->cursor[0], &snode->cursor[1]);
		}
	}
	
	/* store selection in temp test flag */
	for (node = snode->edittree->nodes.first; node; node = node->next) {
		if (node->flag & NODE_SELECT) node->flag |= NODE_TEST;
		else node->flag &= ~NODE_TEST;
	}
	
	node_new = node_add_node(snode, bmain, scene, ntemp, snode->cursor[0], snode->cursor[1]);
	
	/* select previous selection before autoconnect */
	for (node = snode->edittree->nodes.first; node; node = node->next) {
		if (node->flag & NODE_TEST) node->flag |= NODE_SELECT;
	}
	
	/* deselect after autoconnection */
	for (node = snode->edittree->nodes.first; node; node = node->next) {
		if (node->flag & NODE_TEST) node->flag &= ~NODE_SELECT;
	}

	/* once this is called from an operator, this should be removed */
	if (node_new) {
		char undostr[BKE_UNDO_STR_MAX];
		BLI_snprintf(undostr, sizeof(undostr), "Add Node %s", nodeLabel(node_new));
		BKE_write_undo(C, undostr);
	}

	snode_notify(C, snode);
	snode_dag_update(C, snode);
}
Пример #28
0
static void node_menu_add(const bContext *C, Menu *menu)
{
	Scene *scene = CTX_data_scene(C);
	SpaceNode *snode = CTX_wm_space_node(C);
	uiLayout *layout = menu->layout;
	bNodeTreeType *ntreetype = ntreeGetType(snode->treetype);

	if (!snode->nodetree)
		uiLayoutSetActive(layout, FALSE);
	
	uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_DEFAULT);
	uiItemO(layout, "Search ...", 0, "NODE_OT_add_search");
	
	if (ntreetype && ntreetype->foreach_nodeclass)
		ntreetype->foreach_nodeclass(scene, layout, node_menu_add_foreach_cb);
}
Пример #29
0
static int node_view_all_exec(bContext *C, wmOperator *op)
{
    ARegion *ar = CTX_wm_region(C);
    SpaceNode *snode = CTX_wm_space_node(C);
    const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);

    /* is this really needed? */
    snode->xof = 0;
    snode->yof = 0;

    if (space_node_view_flag(C, snode, ar, 0, smooth_viewtx)) {
        return OPERATOR_FINISHED;
    }
    else {
        return OPERATOR_CANCELLED;
    }
}
Пример #30
0
static int node_group_operator_editable(bContext *C)
{
	if (ED_operator_node_editable(C)) {
		SpaceNode *snode = CTX_wm_space_node(C);
		
		/* Group operators only defined for standard node tree types.
		 * Disabled otherwise to allow pynodes define their own operators
		 * with same keymap.
		 */
		if (STREQ(snode->tree_idname, "ShaderNodeTree") ||
		    STREQ(snode->tree_idname, "CompositorNodeTree") ||
		    STREQ(snode->tree_idname, "TextureNodeTree"))
		{
			return true;
		}
	}
	return false;
}