fix: functional node deletion
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "Engine/Operator/GeometryConnection.h"
|
||||
#include "Engine/Network/NetworkManager.h"
|
||||
|
||||
enzo::nt::GeometryConnection::GeometryConnection(enzo::nt::OpId inputOpId, unsigned int inputIndex, enzo::nt::OpId outputOpId, unsigned int outputIndex)
|
||||
:inputOperatorId_{inputOpId}, inputIndex_{inputIndex}, outputOperatorId_{outputOpId}, outputIndex_{outputIndex}
|
||||
@@ -10,3 +11,10 @@ enzo::nt::OpId enzo::nt::GeometryConnection::getOutputOpId() const {return outpu
|
||||
unsigned int enzo::nt::GeometryConnection::getInputIndex() const {return inputIndex_; }
|
||||
unsigned int enzo::nt::GeometryConnection::getOutputIndex() const {return outputIndex_; }
|
||||
|
||||
void enzo::nt::GeometryConnection::remove()
|
||||
{
|
||||
NetworkManager& nm = nt::nm();
|
||||
nm.getGeoOperator(inputOperatorId_).removeOutputConnection(this);
|
||||
nm.getGeoOperator(outputOperatorId_).removeInputConnection(inputIndex_);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,9 @@ public:
|
||||
enzo::nt::OpId getOutputOpId() const;
|
||||
unsigned int getInputIndex() const;
|
||||
unsigned int getOutputIndex() const;
|
||||
|
||||
void remove();
|
||||
// bool isValid();
|
||||
private:
|
||||
enzo::nt::OpId inputOperatorId_;
|
||||
enzo::nt::OpId outputOperatorId_;
|
||||
|
||||
@@ -6,11 +6,12 @@
|
||||
#include "Engine/Parameter/Parameter.h"
|
||||
#include "Engine/Parameter/Template.h"
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include "icecream.hpp"
|
||||
|
||||
using namespace enzo;
|
||||
|
||||
void enzo::nt::connectOperators(enzo::nt::OpId inputOpId, unsigned int inputIndex, enzo::nt::OpId outputOpId, unsigned int outputIndex)
|
||||
std::weak_ptr<nt::GeometryConnection> enzo::nt::connectOperators(enzo::nt::OpId inputOpId, unsigned int inputIndex, enzo::nt::OpId outputOpId, unsigned int outputIndex)
|
||||
{
|
||||
auto& nm = nt::nm();
|
||||
|
||||
@@ -24,6 +25,8 @@ void enzo::nt::connectOperators(enzo::nt::OpId inputOpId, unsigned int inputInde
|
||||
|
||||
// set input on the lower operator
|
||||
outputOp.addInputConnection(newConnection);
|
||||
|
||||
return newConnection;
|
||||
}
|
||||
|
||||
nt::GeometryOperator::GeometryOperator(enzo::nt::OpId opId, op::OpInfo opInfo)
|
||||
@@ -102,6 +105,39 @@ void nt::GeometryOperator::addOutputConnection(std::shared_ptr<nt::GeometryConne
|
||||
std::cout << "size: " << outputConnections_.size() << "\n";
|
||||
}
|
||||
|
||||
void nt::GeometryOperator::removeInputConnection(unsigned int inputIndex)
|
||||
{
|
||||
for(auto it=inputConnections_.begin(); it!=inputConnections_.end(); ++it)
|
||||
{
|
||||
if((*it)->getInputIndex() == inputIndex)
|
||||
{
|
||||
inputConnections_.erase(it);
|
||||
dirtyNode();
|
||||
std::cout << "removing input connection\n";
|
||||
return;
|
||||
}
|
||||
}
|
||||
std::cerr << "Couldn't remove input connection: " << inputIndex << "\n";
|
||||
}
|
||||
|
||||
void nt::GeometryOperator::removeOutputConnection(const nt::GeometryConnection* connectionPtr)
|
||||
{
|
||||
for(auto it=outputConnections_.begin(); it!=outputConnections_.end(); ++it)
|
||||
{
|
||||
const nt::GeometryConnection* otherConnectionPtr = (*it).get();
|
||||
if(connectionPtr == otherConnectionPtr)
|
||||
{
|
||||
outputConnections_.erase(it);
|
||||
dirtyNode();
|
||||
std::cout << "removing output connection\n";
|
||||
return;
|
||||
}
|
||||
}
|
||||
std::cerr << "Couldn't remove output connection\n";
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::weak_ptr<prm::Parameter> nt::GeometryOperator::getParameter(std::string parameterName)
|
||||
{
|
||||
for(auto parm : parameters_)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <memory>
|
||||
|
||||
namespace enzo::nt {
|
||||
void connectOperators(enzo::nt::OpId inputOpId, unsigned int inputIndex, enzo::nt::OpId outputOpId, unsigned int outputIndex);
|
||||
std::weak_ptr<GeometryConnection> connectOperators(enzo::nt::OpId inputOpId, unsigned int inputIndex, enzo::nt::OpId outputOpId, unsigned int outputIndex);
|
||||
|
||||
class GeometryOperator
|
||||
{
|
||||
@@ -20,10 +20,14 @@ public:
|
||||
GeometryOperator& operator=(const GeometryOperator&) = delete;
|
||||
|
||||
void cookOp(op::Context context);
|
||||
geo::Geometry& getOutputGeo(unsigned outputIndex) const;
|
||||
geo::Geometry& getOutputGeo(unsigned int outputIndex) const;
|
||||
|
||||
void addInputConnection(std::shared_ptr<nt::GeometryConnection> connection);
|
||||
void addOutputConnection(std::shared_ptr<nt::GeometryConnection> connection);
|
||||
|
||||
void removeInputConnection(unsigned int inputIndex);
|
||||
void removeOutputConnection(const nt::GeometryConnection* connection);
|
||||
|
||||
std::vector<std::weak_ptr<const GeometryConnection>> getInputConnections() const;
|
||||
std::vector<std::weak_ptr<const GeometryConnection>> getOutputConnections() const;
|
||||
std::optional<const GeometryConnection> getInputConnection(size_t index) const;
|
||||
|
||||
@@ -67,7 +67,7 @@ void Network::deleteEdge(QGraphicsItem* edge)
|
||||
// NOTE: deleting edge kept giving me segmentation faults
|
||||
// I coundn't figure it out so I'm just leaving it for now
|
||||
// delete edge;
|
||||
static_cast<NodeEdgeGraphic*>(edge)->cleanUp();
|
||||
static_cast<NodeEdgeGraphic*>(edge)->remove();
|
||||
std::cout << "finished deleting edge\n----\n";
|
||||
}
|
||||
|
||||
@@ -158,13 +158,12 @@ void Network::socketClicked(SocketGraphic* socket, QMouseEvent *event)
|
||||
std::cout << "CONNECTING opid: " << inputNodeSocket->getOpId() << " -> " << outputNodeSocket->getOpId() << "\n";
|
||||
|
||||
|
||||
nt::connectOperators(inputNodeSocket->getOpId(), inputNodeSocket->getIndex(), outputNodeSocket->getOpId(), outputNodeSocket->getIndex());
|
||||
std::weak_ptr<nt::GeometryConnection> newConnection = nt::connectOperators(inputNodeSocket->getOpId(), inputNodeSocket->getIndex(), outputNodeSocket->getOpId(), outputNodeSocket->getIndex());
|
||||
|
||||
NodeEdgeGraphic* newEdgeGraphic = new NodeEdgeGraphic(outputNodeSocket, inputNodeSocket, newConnection);
|
||||
|
||||
NodeEdgeGraphic* newEdge = new NodeEdgeGraphic(outputNodeSocket, inputNodeSocket);
|
||||
|
||||
newEdge->setPos(outputNodeSocket->scenePos(), inputNodeSocket->scenePos());
|
||||
scene_->addItem(newEdge);
|
||||
newEdgeGraphic->setPos(outputNodeSocket->scenePos(), inputNodeSocket->scenePos());
|
||||
scene_->addItem(newEdgeGraphic);
|
||||
destroyFloatingEdge();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
#include <QGraphicsSceneHoverEvent>
|
||||
#include "icecream.hpp"
|
||||
|
||||
NodeEdgeGraphic::NodeEdgeGraphic(SocketGraphic* socket1, SocketGraphic* socket2, QGraphicsItem *parent)
|
||||
: QGraphicsItem(parent), socket1_{socket1}, socket2_{socket2}, defaultColor_{QColor("white")}
|
||||
NodeEdgeGraphic::NodeEdgeGraphic(SocketGraphic* socket1, SocketGraphic* socket2, std::weak_ptr<enzo::nt::GeometryConnection> connection, QGraphicsItem *parent)
|
||||
: QGraphicsItem(parent), socket1_{socket1}, socket2_{socket2}, defaultColor_{QColor("white")}, connection_{connection}
|
||||
{
|
||||
setAcceptHoverEvents(true);
|
||||
|
||||
@@ -39,7 +39,7 @@ void NodeEdgeGraphic::updateDeleteHighlightPen()
|
||||
NodeEdgeGraphic::~NodeEdgeGraphic()
|
||||
{
|
||||
std::cout << "edge destructor\n";
|
||||
cleanUp();
|
||||
remove();
|
||||
std::cout << "destructor finished\n";
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ void NodeEdgeGraphic::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
|
||||
|
||||
}
|
||||
|
||||
void NodeEdgeGraphic::cleanUp()
|
||||
void NodeEdgeGraphic::remove()
|
||||
{
|
||||
// TODO: possible memory leak
|
||||
// these probably aren't necessary but i'm trying to fix a bug
|
||||
@@ -160,4 +160,9 @@ void NodeEdgeGraphic::cleanUp()
|
||||
scene()->removeItem(this);
|
||||
socket1_->removeEdge(this);
|
||||
socket2_->removeEdge(this);
|
||||
|
||||
if(auto connectionShared = connection_.lock())
|
||||
{
|
||||
connectionShared->remove();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
#pragma once
|
||||
#include <QGraphicsItem>
|
||||
#include "Gui/Network/SocketGraphic.h"
|
||||
#include "Engine/Operator/GeometryConnection.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <memory>
|
||||
|
||||
class NodeEdgeGraphic
|
||||
: public QGraphicsItem
|
||||
{
|
||||
public:
|
||||
NodeEdgeGraphic(SocketGraphic* socket1, SocketGraphic* socket2, QGraphicsItem *parent = nullptr);
|
||||
NodeEdgeGraphic(SocketGraphic* socket1, SocketGraphic* socket2, std::weak_ptr<enzo::nt::GeometryConnection> connection, QGraphicsItem *parent = nullptr);
|
||||
~NodeEdgeGraphic();
|
||||
QRectF boundingRect() const override;
|
||||
|
||||
@@ -20,7 +22,7 @@ public:
|
||||
void setPos(QPointF pos1, QPointF pos2);
|
||||
void setStartPos(QPointF pos);
|
||||
void setEndPos(QPointF pos);
|
||||
void cleanUp();
|
||||
void remove();
|
||||
void setDeleteHighlight(bool state);
|
||||
QPen deleteHighlightPen_;
|
||||
QPen defaultPen_;
|
||||
@@ -41,6 +43,8 @@ private:
|
||||
qreal padding_=40;
|
||||
QPointF hoverPos_;
|
||||
|
||||
std::weak_ptr<enzo::nt::GeometryConnection> connection_;
|
||||
|
||||
void updatePath();
|
||||
protected:
|
||||
void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
|
||||
|
||||
@@ -32,7 +32,7 @@ void SocketGraphic::addEdge(NodeEdgeGraphic* edge)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
edge->cleanUp();
|
||||
edge->remove();
|
||||
}
|
||||
edges_.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user