Skip to content

Commit 1b9614f

Browse files
author
Roberto De Ioris
committed
added preliminary support for graph pins
1 parent 2e442bd commit 1b9614f

6 files changed

Lines changed: 131 additions & 0 deletions

File tree

‎Source/UnrealEnginePython/Private/UEPyEdGraph.cpp‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,21 @@ PyObject *py_ue_graph_add_node_variable_set(ue_PyUObject * self, PyObject * args
205205
return ret;
206206

207207
}
208+
209+
PyObject *py_ue_node_pins(ue_PyUObject * self, PyObject * args) {
210+
211+
ue_py_check(self);
212+
213+
if (!self->ue_object->IsA<UEdGraphNode>()) {
214+
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraphNode");
215+
}
216+
217+
UEdGraphNode *node = (UEdGraphNode *)self->ue_object;
218+
219+
PyObject *pins_list = PyList_New(0);
220+
for (UEdGraphPin *pin : node->Pins) {
221+
PyList_Append(pins_list, (PyObject *)py_ue_new_edgraphpin(pin));
222+
}
223+
return pins_list;
224+
}
208225
#endif

‎Source/UnrealEnginePython/Private/UEPyEdGraph.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ PyObject *py_ue_graph_add_node_call_function(ue_PyUObject *, PyObject *);
99
PyObject *py_ue_graph_add_node_custom_event(ue_PyUObject *, PyObject *);
1010
PyObject *py_ue_graph_add_node_variable_get(ue_PyUObject *, PyObject *);
1111
PyObject *py_ue_graph_add_node_variable_set(ue_PyUObject *, PyObject *);
12+
13+
PyObject *py_ue_node_pins(ue_PyUObject *, PyObject *);
1214
#endif
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
2+
#if WITH_EDITOR
3+
4+
5+
#include "UnrealEnginePythonPrivatePCH.h"
6+
#include "Runtime/Engine/Classes/EdGraph/EdGraphPin.h"
7+
8+
static PyObject *py_ue_edgraphpin_make_link_to(ue_PyEdGraphPin *self, PyObject * args) {
9+
Py_INCREF(Py_None);
10+
return Py_None;
11+
}
12+
13+
static PyMethodDef ue_PyEdGraphPin_methods[] = {
14+
{ "make_link_to", (PyCFunction)py_ue_edgraphpin_make_link_to, METH_VARARGS, "" },
15+
{ NULL } /* Sentinel */
16+
};
17+
18+
static PyObject *py_ue_edgraphpin_get_name(ue_PyEdGraphPin *self, void *closure) {
19+
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->pin->PinName)));
20+
}
21+
22+
static PyGetSetDef ue_PyEdGraphPin_getseters[] = {
23+
{ (char*)"name", (getter)py_ue_edgraphpin_get_name, NULL, (char *)"", NULL },
24+
{ NULL } /* Sentinel */
25+
};
26+
27+
static PyObject *ue_PyEdGraphPin_str(ue_PyEdGraphPin *self)
28+
{
29+
return PyUnicode_FromFormat("<unreal_engine.EdGraphPin {'name': '%s', 'type': '%s'}>",
30+
TCHAR_TO_UTF8(*self->pin->PinName), TCHAR_TO_UTF8(*self->pin->PinType.PinCategory));
31+
}
32+
33+
static PyTypeObject ue_PyEdGraphPinType = {
34+
PyVarObject_HEAD_INIT(NULL, 0)
35+
"unreal_engine.EdGraphPin", /* tp_name */
36+
sizeof(ue_PyEdGraphPin), /* tp_basicsize */
37+
0, /* tp_itemsize */
38+
0, /* tp_dealloc */
39+
0, /* tp_print */
40+
0, /* tp_getattr */
41+
0, /* tp_setattr */
42+
0, /* tp_reserved */
43+
0, /* tp_repr */
44+
0, /* tp_as_number */
45+
0, /* tp_as_sequence */
46+
0, /* tp_as_mapping */
47+
0, /* tp_hash */
48+
0, /* tp_call */
49+
(reprfunc)ue_PyEdGraphPin_str, /* tp_str */
50+
0, /* tp_getattro */
51+
0, /* tp_setattro */
52+
0, /* tp_as_buffer */
53+
Py_TPFLAGS_DEFAULT, /* tp_flags */
54+
"Unreal Engine Editor GraphPin", /* tp_doc */
55+
0, /* tp_traverse */
56+
0, /* tp_clear */
57+
0, /* tp_richcompare */
58+
0, /* tp_weaklistoffset */
59+
0, /* tp_iter */
60+
0, /* tp_iternext */
61+
ue_PyEdGraphPin_methods, /* tp_methods */
62+
0,
63+
ue_PyEdGraphPin_getseters,
64+
};
65+
66+
67+
void ue_python_init_edgraphpin(PyObject *ue_module) {
68+
ue_PyEdGraphPinType.tp_new = PyType_GenericNew;
69+
70+
if (PyType_Ready(&ue_PyEdGraphPinType) < 0)
71+
return;
72+
73+
Py_INCREF(&ue_PyEdGraphPinType);
74+
PyModule_AddObject(ue_module, "EdGraphPin", (PyObject *)&ue_PyEdGraphPinType);
75+
}
76+
77+
PyObject *py_ue_new_edgraphpin(UEdGraphPin *pin) {
78+
ue_PyEdGraphPin *ret = (ue_PyEdGraphPin *)PyObject_New(ue_PyEdGraphPin, &ue_PyEdGraphPinType);
79+
ret->pin = pin;
80+
return (PyObject *)ret;
81+
}
82+
83+
ue_PyEdGraphPin *py_ue_is_edgraphpin(PyObject *obj) {
84+
if (!PyObject_IsInstance(obj, (PyObject *)&ue_PyEdGraphPinType))
85+
return nullptr;
86+
return (ue_PyEdGraphPin *)obj;
87+
}
88+
89+
#endif
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#pragma once
2+
3+
#if WITH_EDITOR
4+
5+
#include "UnrealEnginePython.h"
6+
7+
#include "Runtime/Engine/Classes/EdGraph/EdGraphPin.h"
8+
9+
typedef struct {
10+
PyObject_HEAD
11+
/* Type-specific fields go here. */
12+
UEdGraphPin *pin;
13+
} ue_PyEdGraphPin;
14+
15+
PyObject *py_ue_new_edgraphpin(UEdGraphPin *);
16+
ue_PyEdGraphPin *py_ue_is_edgrahpin(PyObject *);
17+
18+
void ue_python_init_edgraphpin(PyObject *);
19+
#endif

‎Source/UnrealEnginePython/Private/UEPyModule.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ static PyMethodDef ue_PyUObject_methods[] = {
312312
{ "graph_add_node_custom_event", (PyCFunction)py_ue_graph_add_node_custom_event, METH_VARARGS, "" },
313313
{ "graph_add_node_variable_get", (PyCFunction)py_ue_graph_add_node_variable_get, METH_VARARGS, "" },
314314
{ "graph_add_node_variable_set", (PyCFunction)py_ue_graph_add_node_variable_set, METH_VARARGS, "" },
315+
316+
{ "node_pins", (PyCFunction)py_ue_node_pins, METH_VARARGS, "" },
315317
#endif
316318

317319
{ "is_rooted", (PyCFunction)py_ue_is_rooted, METH_VARARGS, "" },
@@ -1040,6 +1042,7 @@ void unreal_engine_init_py_module() {
10401042
ue_python_init_swidget(new_unreal_engine_module);
10411043
ue_python_init_farfilter(new_unreal_engine_module);
10421044
ue_python_init_fassetdata(new_unreal_engine_module);
1045+
ue_python_init_edgraphpin(new_unreal_engine_module);
10431046
#endif
10441047

10451048
PyObject *py_sys = PyImport_ImportModule("sys");

‎Source/UnrealEnginePython/Private/UnrealEnginePythonPrivatePCH.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "UEPyFAssetData.h"
4444
#include "UEPyFARFilter.h"
4545
#include "UEPyAnimSequence.h"
46+
#include "UEPyEdGraphPin.h"
4647
#endif
4748

4849
#define ue_py_check(py_u) if (!py_u->ue_object || !py_u->ue_object->IsValidLowLevel() || py_u->ue_object->IsPendingKillOrUnreachable())\

0 commit comments

Comments
 (0)