Skip to content

Commit dbfde5d

Browse files
author
Roberto De Ioris
committed
improved pin api
1 parent 1b9614f commit dbfde5d

5 files changed

Lines changed: 80 additions & 1 deletion

File tree

Source/UnrealEnginePython/Private/UEPyEdGraph.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ PyObject *py_ue_graph_add_node_call_function(ue_PyUObject * self, PyObject * arg
5959
UEdGraphSchema_K2::SetNodeMetaData(node, FNodeMetadata::DefaultGraphNode);
6060
graph->AddNode(node);
6161

62+
node->MarkPackageDirty();
63+
6264
PyObject *ret = (PyObject *)ue_get_python_wrapper(node);
6365
if (!ret)
6466
return PyErr_Format(PyExc_Exception, "uobject is in invalid state");
@@ -96,6 +98,8 @@ PyObject *py_ue_graph_add_node_custom_event(ue_PyUObject * self, PyObject * args
9698
UEdGraphSchema_K2::SetNodeMetaData(node, FNodeMetadata::DefaultGraphNode);
9799
graph->AddNode(node);
98100

101+
node->MarkPackageDirty();
102+
99103
PyObject *ret = (PyObject *)ue_get_python_wrapper(node);
100104
if (!ret)
101105
return PyErr_Format(PyExc_Exception, "uobject is in invalid state");
@@ -147,6 +151,8 @@ PyObject *py_ue_graph_add_node_variable_get(ue_PyUObject * self, PyObject * args
147151
FEdGraphSchemaAction_K2NewNode::SpawnNodeFromTemplate<UK2Node_VariableGet>(graph, node, FVector2D(x, y));
148152
//graph->AddNode(node);
149153

154+
node->MarkPackageDirty();
155+
150156
PyObject *ret = (PyObject *)ue_get_python_wrapper(node);
151157
if (!ret)
152158
return PyErr_Format(PyExc_Exception, "uobject is in invalid state");
@@ -198,6 +204,8 @@ PyObject *py_ue_graph_add_node_variable_set(ue_PyUObject * self, PyObject * args
198204
FEdGraphSchemaAction_K2NewNode::SpawnNodeFromTemplate<UK2Node_VariableSet>(graph, node, FVector2D(x, y));
199205
//graph->AddNode(node);
200206

207+
node->MarkPackageDirty();
208+
201209
PyObject *ret = (PyObject *)ue_get_python_wrapper(node);
202210
if (!ret)
203211
return PyErr_Format(PyExc_Exception, "uobject is in invalid state");
@@ -222,4 +230,29 @@ PyObject *py_ue_node_pins(ue_PyUObject * self, PyObject * args) {
222230
}
223231
return pins_list;
224232
}
233+
234+
PyObject *py_ue_node_find_pin(ue_PyUObject * self, PyObject * args) {
235+
236+
ue_py_check(self);
237+
238+
char *name = nullptr;
239+
if (!PyArg_ParseTuple(args, "s:node_find_pin", &name)) {
240+
return NULL;
241+
}
242+
243+
if (!self->ue_object->IsA<UEdGraphNode>()) {
244+
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraphNode");
245+
}
246+
247+
UEdGraphNode *node = (UEdGraphNode *)self->ue_object;
248+
249+
UEdGraphPin *pin = node->FindPin(UTF8_TO_TCHAR(name));
250+
if (!pin) {
251+
return PyErr_Format(PyExc_Exception, "unable to find pin \"%s\"", name);
252+
}
253+
254+
PyObject *ret = py_ue_new_edgraphpin(pin);
255+
Py_INCREF(ret);
256+
return ret;
257+
}
225258
#endif

Source/UnrealEnginePython/Private/UEPyEdGraph.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ PyObject *py_ue_graph_add_node_variable_get(ue_PyUObject *, PyObject *);
1111
PyObject *py_ue_graph_add_node_variable_set(ue_PyUObject *, PyObject *);
1212

1313
PyObject *py_ue_node_pins(ue_PyUObject *, PyObject *);
14+
PyObject *py_ue_node_find_pin(ue_PyUObject *, PyObject *);
1415
#endif

Source/UnrealEnginePython/Private/UEPyEdGraphPin.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,65 @@
66
#include "Runtime/Engine/Classes/EdGraph/EdGraphPin.h"
77

88
static PyObject *py_ue_edgraphpin_make_link_to(ue_PyEdGraphPin *self, PyObject * args) {
9+
PyObject *other_pin;
10+
if (!PyArg_ParseTuple(args, "O:make_link_to", &other_pin)) {
11+
return NULL;
12+
}
13+
14+
ue_PyEdGraphPin *py_other_pin = py_ue_is_edgraphpin(other_pin);
15+
if (!py_other_pin) {
16+
return PyErr_Format(PyExc_Exception, "argument is not a UEdGraphPin");
17+
}
18+
19+
self->pin->MakeLinkTo(py_other_pin->pin);
20+
21+
self->pin->Modify(true);
22+
23+
Py_INCREF(Py_None);
24+
return Py_None;
25+
}
26+
27+
static PyObject *py_ue_edgraphpin_break_link_to(ue_PyEdGraphPin *self, PyObject * args) {
28+
PyObject *other_pin;
29+
if (!PyArg_ParseTuple(args, "O:break_link_to", &other_pin)) {
30+
return NULL;
31+
}
32+
33+
ue_PyEdGraphPin *py_other_pin = py_ue_is_edgraphpin(other_pin);
34+
if (!py_other_pin) {
35+
return PyErr_Format(PyExc_Exception, "argument is not a UEdGraphPin");
36+
}
37+
38+
self->pin->BreakLinkTo(py_other_pin->pin);
39+
40+
self->pin->Modify(true);
41+
942
Py_INCREF(Py_None);
1043
return Py_None;
1144
}
1245

1346
static PyMethodDef ue_PyEdGraphPin_methods[] = {
1447
{ "make_link_to", (PyCFunction)py_ue_edgraphpin_make_link_to, METH_VARARGS, "" },
48+
{ "break_link_to", (PyCFunction)py_ue_edgraphpin_break_link_to, METH_VARARGS, "" },
1549
{ NULL } /* Sentinel */
1650
};
1751

1852
static PyObject *py_ue_edgraphpin_get_name(ue_PyEdGraphPin *self, void *closure) {
1953
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->pin->PinName)));
2054
}
2155

56+
static PyObject *py_ue_edgraphpin_get_category(ue_PyEdGraphPin *self, void *closure) {
57+
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->pin->PinType.PinCategory)));
58+
}
59+
60+
static PyObject *py_ue_edgraphpin_get_sub_category(ue_PyEdGraphPin *self, void *closure) {
61+
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->pin->PinType.PinSubCategory)));
62+
}
63+
2264
static PyGetSetDef ue_PyEdGraphPin_getseters[] = {
2365
{ (char*)"name", (getter)py_ue_edgraphpin_get_name, NULL, (char *)"", NULL },
66+
{ (char*)"category", (getter)py_ue_edgraphpin_get_category, NULL, (char *)"", NULL },
67+
{ (char*)"sub_category", (getter)py_ue_edgraphpin_get_sub_category, NULL, (char *)"", NULL },
2468
{ NULL } /* Sentinel */
2569
};
2670

Source/UnrealEnginePython/Private/UEPyEdGraphPin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ typedef struct {
1313
} ue_PyEdGraphPin;
1414

1515
PyObject *py_ue_new_edgraphpin(UEdGraphPin *);
16-
ue_PyEdGraphPin *py_ue_is_edgrahpin(PyObject *);
16+
ue_PyEdGraphPin *py_ue_is_edgraphpin(PyObject *);
1717

1818
void ue_python_init_edgraphpin(PyObject *);
1919
#endif

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ static PyMethodDef ue_PyUObject_methods[] = {
314314
{ "graph_add_node_variable_set", (PyCFunction)py_ue_graph_add_node_variable_set, METH_VARARGS, "" },
315315

316316
{ "node_pins", (PyCFunction)py_ue_node_pins, METH_VARARGS, "" },
317+
{ "node_find_pin", (PyCFunction)py_ue_node_find_pin, METH_VARARGS, "" },
317318
#endif
318319

319320
{ "is_rooted", (PyCFunction)py_ue_is_rooted, METH_VARARGS, "" },

0 commit comments

Comments
 (0)