diff --git a/modules/editor/grapheditor/editor/graph/abstractnodegraph.cpp b/modules/editor/grapheditor/editor/graph/abstractnodegraph.cpp index 8b4b9c1e3..982e29089 100644 --- a/modules/editor/grapheditor/editor/graph/abstractnodegraph.cpp +++ b/modules/editor/grapheditor/editor/graph/abstractnodegraph.cpp @@ -1,6 +1,7 @@ #include "abstractnodegraph.h" #include "graphnode.h" +#include "graphwidgets/nodewidget.h" #include @@ -42,6 +43,7 @@ void AbstractNodeGraph::nodeDelete(GraphNode *node) { linkDelete(node); it = m_nodes.erase(it); + delete node->widget(); delete node; break; } else { @@ -85,9 +87,6 @@ void AbstractNodeGraph::linkDelete(NodePort *port) { while(it != m_links.end()) { Link *link = *it; if(link->oport == port || link->iport == port) { - GraphNode *first = link->sender; - GraphNode *second = link->receiver; - it = m_links.erase(it); delete link; } else { @@ -101,10 +100,6 @@ void AbstractNodeGraph::linkDelete(GraphNode *node) { while(it != m_links.end()) { Link *link = *it; if(link->sender == node || link->receiver == node) { - GraphNode *second = link->sender; - if(link->sender == node) { - second = link->receiver; - } it = m_links.erase(it); delete link; } else { @@ -117,9 +112,6 @@ void AbstractNodeGraph::linkDelete(Link *link) { auto it = m_links.begin(); while(it != m_links.end()) { if(*it == link) { - GraphNode *first = link->sender; - GraphNode *second = link->receiver; - m_links.erase(it); delete link; @@ -339,7 +331,7 @@ const AbstractNodeGraph::LinkList &AbstractNodeGraph::links() const { } void AbstractNodeGraph::graphUpdated() { - emitSignal(_SIGNAL(graphUpdated())); + emitSignal(_SIGNAL(graphUpdated())); } void AbstractNodeGraph::graphLoaded() { diff --git a/modules/editor/grapheditor/editor/graph/actions/changenodeproperty.cpp b/modules/editor/grapheditor/editor/graph/actions/changenodeproperty.cpp index f64bf01e2..1145ed33e 100644 --- a/modules/editor/grapheditor/editor/graph/actions/changenodeproperty.cpp +++ b/modules/editor/grapheditor/editor/graph/actions/changenodeproperty.cpp @@ -13,7 +13,7 @@ ChangeNodeProperty::ChangeNodeProperty(const Object::ObjectList &objects, const } void ChangeNodeProperty::undo() { - ChangeNodeProperty::redo(); + redo(); } void ChangeNodeProperty::redo() { @@ -31,7 +31,7 @@ void ChangeNodeProperty::redo() { } } - auto g = m_controller->graph(); + AbstractNodeGraph *g = m_controller->graph(); - g->emitSignal(_SIGNAL(graphUpdated())); + g->graphUpdated(); } diff --git a/modules/editor/grapheditor/editor/graph/actions/createlink.cpp b/modules/editor/grapheditor/editor/graph/actions/createlink.cpp index cd48f7ac8..c3033746f 100644 --- a/modules/editor/grapheditor/editor/graph/actions/createlink.cpp +++ b/modules/editor/grapheditor/editor/graph/actions/createlink.cpp @@ -12,18 +12,18 @@ CreateLink::CreateLink(int sender, int oport, int receiver, int iport, GraphCont } void CreateLink::undo() { - auto g = m_controller->graph(); + AbstractNodeGraph *g = m_controller->graph(); AbstractNodeGraph::Link *link = g->link(m_index); if(link) { g->linkDelete(link); - g->emitSignal(_SIGNAL(graphUpdated())); + g->graphUpdated(); } } void CreateLink::redo() { - auto g = m_controller->graph(); + AbstractNodeGraph *g = m_controller->graph(); GraphNode *snd = g->node(m_sender); GraphNode *rcv = g->node(m_receiver); @@ -31,9 +31,8 @@ void CreateLink::redo() { NodePort *op = (m_oPort > -1) ? snd->port(m_oPort) : nullptr; NodePort *ip = (m_iPort > -1) ? rcv->port(m_iPort) : nullptr; - AbstractNodeGraph::Link *link = g->linkCreate(snd, op, rcv, ip); - m_index = g->link(link); + m_index = g->link(g->linkCreate(snd, op, rcv, ip)); - g->emitSignal(_SIGNAL(graphUpdated())); + g->graphUpdated(); } } diff --git a/modules/editor/grapheditor/editor/graph/actions/createnode.cpp b/modules/editor/grapheditor/editor/graph/actions/createnode.cpp index 7a19a1544..dca5197bb 100644 --- a/modules/editor/grapheditor/editor/graph/actions/createnode.cpp +++ b/modules/editor/grapheditor/editor/graph/actions/createnode.cpp @@ -14,15 +14,15 @@ CreateNode::CreateNode(const std::string &type, int x, int y, GraphController *c } void CreateNode::undo() { - auto g = m_controller->graph(); + AbstractNodeGraph *g = m_controller->graph(); g->nodeDelete(g->node(m_node)); m_controller->selectNodes(m_list); - g->emitSignal(_SIGNAL(graphUpdated())); + g->graphUpdated(); } void CreateNode::redo() { - auto g = m_controller->graph(); + AbstractNodeGraph *g = m_controller->graph(); GraphNode *node = g->nodeCreate(m_type, m_linkIndex); if(node) { node->setPosition(m_point); @@ -54,8 +54,7 @@ void CreateNode::redo() { NodePort *sp = (m_fromPort > -1) ? ((m_out) ? item : snd->firstPort(!m_out)) : nullptr; NodePort *rp = (m_fromPort > -1) ? ((m_out) ? rcv->firstPort(!m_out) : item) : nullptr; - AbstractNodeGraph::Link *link = g->linkCreate(snd, sp, rcv, rp); - m_linkIndex = g->link(link); + m_linkIndex = g->link(g->linkCreate(snd, sp, rcv, rp)); } } @@ -66,5 +65,5 @@ void CreateNode::redo() { m_controller->selectNodes({m_node}); - g->emitSignal(_SIGNAL(graphUpdated())); + g->graphUpdated(); } diff --git a/modules/editor/grapheditor/editor/graph/actions/deletelinksbyport.cpp b/modules/editor/grapheditor/editor/graph/actions/deletelinksbyport.cpp index 37f85f7c9..b2f37ba86 100644 --- a/modules/editor/grapheditor/editor/graph/actions/deletelinksbyport.cpp +++ b/modules/editor/grapheditor/editor/graph/actions/deletelinksbyport.cpp @@ -9,11 +9,9 @@ DeleteLinksByPort::DeleteLinksByPort(int node, int port, GraphController *ctrl, } void DeleteLinksByPort::undo() { - auto g = m_controller->graph(); - - for(int i = 0; i < m_links.size(); ++i) { - Link link = *std::next(m_links.begin(), i); + AbstractNodeGraph *g = m_controller->graph(); + for(Link &link : m_links) { GraphNode *snd = g->node(link.sender); GraphNode *rcv = g->node(link.receiver); if(snd && rcv) { @@ -23,11 +21,11 @@ void DeleteLinksByPort::undo() { g->linkCreate(snd, op, rcv, ip); } } - g->emitSignal(_SIGNAL(graphUpdated())); + g->graphUpdated(); } void DeleteLinksByPort::redo() { - auto g = m_controller->graph(); + AbstractNodeGraph *g = m_controller->graph(); GraphNode *node = g->node(m_node); if(node) { @@ -52,6 +50,6 @@ void DeleteLinksByPort::redo() { } g->linkDelete(item); } - g->emitSignal(_SIGNAL(graphUpdated())); + g->graphUpdated(); } } diff --git a/modules/editor/grapheditor/editor/graph/actions/deletenodes.cpp b/modules/editor/grapheditor/editor/graph/actions/deletenodes.cpp index a9476d700..d84abc98e 100644 --- a/modules/editor/grapheditor/editor/graph/actions/deletenodes.cpp +++ b/modules/editor/grapheditor/editor/graph/actions/deletenodes.cpp @@ -9,14 +9,17 @@ DeleteNodes::DeleteNodes(const std::list &selection, GraphController *c } void DeleteNodes::undo() { - m_controller->graph()->loadGraph(m_document.first_child()); + AbstractNodeGraph *g = m_controller->graph(); + + g->loadGraph(m_document.first_child()); m_controller->selectNodes(m_indices); + g->graphUpdated(); } void DeleteNodes::redo() { m_document.reset(); - auto g = m_controller->graph(); + AbstractNodeGraph *g = m_controller->graph(); pugi::xml_node graphElement = m_document.append_child("graph"); @@ -38,5 +41,5 @@ void DeleteNodes::redo() { g->nodeDelete(it); } - g->emitSignal(_SIGNAL(graphUpdated())); + g->graphUpdated(); } diff --git a/modules/editor/grapheditor/editor/graph/actions/movenodes.cpp b/modules/editor/grapheditor/editor/graph/actions/movenodes.cpp index c9c8285e1..eed4cb3be 100644 --- a/modules/editor/grapheditor/editor/graph/actions/movenodes.cpp +++ b/modules/editor/grapheditor/editor/graph/actions/movenodes.cpp @@ -8,7 +8,7 @@ MoveNodes::MoveNodes(const std::list &selection, GraphController * UndoCommand(name, parent), m_controller(ctrl) { - auto g = m_controller->graph(); + AbstractNodeGraph *g = m_controller->graph(); m_indices.reserve(selection.size()); m_points.reserve(selection.size()); @@ -26,7 +26,7 @@ void MoveNodes::undo() { } void MoveNodes::redo() { - auto g = m_controller->graph(); + AbstractNodeGraph *g = m_controller->graph(); std::vector positions(m_indices.size()); for(int i = 0; i < m_indices.size(); i++) { diff --git a/modules/editor/grapheditor/editor/graph/actions/pastenodes.cpp b/modules/editor/grapheditor/editor/graph/actions/pastenodes.cpp index 64983d722..4c39e702d 100644 --- a/modules/editor/grapheditor/editor/graph/actions/pastenodes.cpp +++ b/modules/editor/grapheditor/editor/graph/actions/pastenodes.cpp @@ -13,17 +13,17 @@ PasteNodes::PasteNodes(const std::string &data, int x, int y, GraphController *c void PasteNodes::undo() { m_list.reverse(); - auto g = m_controller->graph(); + AbstractNodeGraph *g = m_controller->graph(); for(auto &it : m_list) { g->nodeDelete(g->node(it)); } m_controller->selectNodes(m_lastSelect); - g->emitSignal(_SIGNAL(graphUpdated())); + g->graphUpdated(); } void PasteNodes::redo() { - auto g = m_controller->graph(); + AbstractNodeGraph *g = m_controller->graph(); Vector2 maxPos(-FLT_MAX, -FLT_MAX); @@ -62,5 +62,5 @@ void PasteNodes::redo() { m_controller->selectNodes(m_list); - g->emitSignal(_SIGNAL(graphUpdated())); + g->graphUpdated(); } diff --git a/modules/editor/grapheditor/editor/graph/actions/selectnodes.cpp b/modules/editor/grapheditor/editor/graph/actions/selectnodes.cpp index 42e534ba5..67965ea56 100644 --- a/modules/editor/grapheditor/editor/graph/actions/selectnodes.cpp +++ b/modules/editor/grapheditor/editor/graph/actions/selectnodes.cpp @@ -12,7 +12,7 @@ void SelectNodes::undo() { } void SelectNodes::redo() { - auto g = m_controller->graph(); + AbstractNodeGraph *g = m_controller->graph(); std::list list; for(auto it : m_controller->selected()) { diff --git a/modules/editor/grapheditor/editor/graph/graphnode.cpp b/modules/editor/grapheditor/editor/graph/graphnode.cpp index 148bb3c38..321fb191b 100644 --- a/modules/editor/grapheditor/editor/graph/graphnode.cpp +++ b/modules/editor/grapheditor/editor/graph/graphnode.cpp @@ -29,10 +29,6 @@ GraphNode::GraphNode() : } -GraphNode::~GraphNode() { - delete m_nodeWidget; -} - AbstractNodeGraph *GraphNode::graph() const { return m_graph; } @@ -112,7 +108,7 @@ Widget *GraphNode::widget() { Widget *GraphNode::portWidget(int port) { NodePort *p = GraphNode::port(port); if(p) { - return reinterpret_cast(p->m_userData); + return p->m_widget; } return nullptr; } diff --git a/modules/editor/grapheditor/editor/graph/graphnode.h b/modules/editor/grapheditor/editor/graph/graphnode.h index b5271669b..58f3ffb63 100644 --- a/modules/editor/grapheditor/editor/graph/graphnode.h +++ b/modules/editor/grapheditor/editor/graph/graphnode.h @@ -47,7 +47,7 @@ class NODEGRAPH_EXPORT NodePort { GraphNode *m_node; - void *m_userData = nullptr; + Widget *m_widget = nullptr; uint32_t m_type; @@ -66,7 +66,6 @@ class NODEGRAPH_EXPORT GraphNode : public Object { public: GraphNode(); - ~GraphNode(); AbstractNodeGraph *graph() const; void setGraph(AbstractNodeGraph *graph); diff --git a/modules/editor/grapheditor/editor/graph/graphview.cpp b/modules/editor/grapheditor/editor/graph/graphview.cpp index 7ac807bb0..ae52c464e 100644 --- a/modules/editor/grapheditor/editor/graph/graphview.cpp +++ b/modules/editor/grapheditor/editor/graph/graphview.cpp @@ -5,7 +5,6 @@ #include "graphnode.h" #include "graphcontroller.h" -#include "nodegroup.h" #include "graphwidgets/nodewidget.h" #include "graphwidgets/groupwidget.h" #include "graphwidgets/portwidget.h" @@ -231,7 +230,7 @@ void GraphView::buildLink(NodeWidget *node, int port) { m_editor->undoRedo()->push(new CreateLink(g->node(n1), n1->portPosition(p1), g->node(n2), port, ctrl)); NodePort *p2 = n2->port(port); if(p2) { - PortWidget *w2 = reinterpret_cast(p2->m_userData); + PortWidget *w2 = static_cast(p2->m_widget); if(w2) { w2->portUpdate(); } @@ -265,10 +264,10 @@ void GraphView::deleteLink(NodeWidget *node, int port) { std::list widgets; if(p1) { - widgets = {reinterpret_cast(p1->m_userData)}; + widgets = {static_cast(p1->m_widget)}; for(auto it : g->findLinks(p1)) { if(it->oport == p1 && it->iport) { - widgets.push_back(reinterpret_cast(it->iport->m_userData)); + widgets.push_back(static_cast(it->iport->m_widget)); } } } diff --git a/modules/editor/grapheditor/editor/graph/graphwidgets/linksrender.cpp b/modules/editor/grapheditor/editor/graph/graphwidgets/linksrender.cpp index c04039ad1..d77364e6c 100644 --- a/modules/editor/grapheditor/editor/graph/graphwidgets/linksrender.cpp +++ b/modules/editor/grapheditor/editor/graph/graphwidgets/linksrender.cpp @@ -143,7 +143,7 @@ void LinksRender::composeLinks() { bool state = false; Vector3 s; if(it->oport) { - PortWidget *widget = reinterpret_cast(it->oport->m_userData); + PortWidget *widget = static_cast(it->oport->m_widget); if(widget) { RectTransform *rect = widget->knob()->rectTransform(); Matrix4 m(rect->worldTransform()); @@ -151,7 +151,7 @@ void LinksRender::composeLinks() { } } else { state = true; - RectTransform *rect = reinterpret_cast(it->sender->widget())->rectTransform(); + RectTransform *rect = static_cast(it->sender->widget())->rectTransform(); Matrix4 m(rect->worldTransform()); s = worlToView * (m * Vector3(rect->size() * 0.5f, 0.0f)); } @@ -161,7 +161,7 @@ void LinksRender::composeLinks() { Vector3 e; if(it->iport) { - PortWidget *widget = reinterpret_cast(it->iport->m_userData); + PortWidget *widget = static_cast(it->iport->m_widget); if(widget) { RectTransform *rect = widget->knob()->rectTransform(); Matrix4 m(rect->worldTransform()); @@ -172,7 +172,7 @@ void LinksRender::composeLinks() { } } else { state = true; - RectTransform *rect = reinterpret_cast(it->receiver->widget())->rectTransform(); + RectTransform *rect = static_cast(it->receiver->widget())->rectTransform(); Matrix4 m(rect->worldTransform()); Vector3 h(rect->size() * 0.5f, 0.0f); e = worlToView * (m * h); diff --git a/modules/editor/grapheditor/editor/graph/graphwidgets/nodewidget.cpp b/modules/editor/grapheditor/editor/graph/graphwidgets/nodewidget.cpp index 683926d6f..45a09062d 100644 --- a/modules/editor/grapheditor/editor/graph/graphwidgets/nodewidget.cpp +++ b/modules/editor/grapheditor/editor/graph/graphwidgets/nodewidget.cpp @@ -3,7 +3,6 @@ #include "portwidget.h" #include "../graphnode.h" -#include "../abstractnodegraph.h" #include "../graphview.h" #include "../graphcontroller.h" diff --git a/modules/editor/grapheditor/editor/graph/graphwidgets/portwidget.cpp b/modules/editor/grapheditor/editor/graph/graphwidgets/portwidget.cpp index 82582fd76..0012cc4fd 100644 --- a/modules/editor/grapheditor/editor/graph/graphwidgets/portwidget.cpp +++ b/modules/editor/grapheditor/editor/graph/graphwidgets/portwidget.cpp @@ -1,7 +1,6 @@ #include "portwidget.h" #include "../graphnode.h" -#include "../graphcontroller.h" #include "../abstractnodegraph.h" #include @@ -20,6 +19,12 @@ PortWidget::PortWidget() : } +PortWidget::~PortWidget() { + if(m_port) { + m_port->m_widget = nullptr; + } +} + void PortWidget::portUpdate() { GraphNode *node = m_port->m_node; if(node) { @@ -42,7 +47,7 @@ NodePort *PortWidget::port() const { void PortWidget::setNodePort(NodePort *port) { m_port = port; - m_port->m_userData = this; + m_port->m_widget = this; RectTransform *rect = rectTransform(); if(m_knob) { diff --git a/modules/editor/grapheditor/editor/graph/graphwidgets/portwidget.h b/modules/editor/grapheditor/editor/graph/graphwidgets/portwidget.h index 602d360bf..87ce51eb9 100644 --- a/modules/editor/grapheditor/editor/graph/graphwidgets/portwidget.h +++ b/modules/editor/grapheditor/editor/graph/graphwidgets/portwidget.h @@ -15,6 +15,7 @@ class PortWidget : public Widget { public: PortWidget(); + ~PortWidget(); void portUpdate(); diff --git a/modules/editor/shadertools/converter/shadergraph.cpp b/modules/editor/shadertools/converter/shadergraph.cpp index 171a6e6b8..1177f827a 100644 --- a/modules/editor/shadertools/converter/shadergraph.cpp +++ b/modules/editor/shadertools/converter/shadergraph.cpp @@ -347,13 +347,15 @@ void ShaderGraph::onNodesLoaded() { } } - int i = 0; - for(auto &it : m_inputs) { - NodePort port(m_rootNode, false, (uint32_t)it.m_value.type(), i, it.m_name, - ShaderNode::m_portColors[(uint32_t)it.m_value.type()], it.m_value); - port.m_userFlags = it.m_vertex ? Vertex : Fragment; - m_rootNode->ports().push_back(port); - i++; + if(m_rootNode->ports().empty()) { + int i = 0; + for(auto &it : m_inputs) { + NodePort port(m_rootNode, false, (uint32_t)it.m_value.type(), i, it.m_name, + ShaderNode::m_portColors[(uint32_t)it.m_value.type()], it.m_value); + port.m_userFlags = it.m_vertex ? Vertex : Fragment; + m_rootNode->ports().push_back(port); + i++; + } } }