fix: connection switching
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
#include "Engine/Operator/GeometryConnection.h"
|
#include "Engine/Operator/GeometryConnection.h"
|
||||||
#include "Engine/Network/NetworkManager.h"
|
#include "Engine/Network/NetworkManager.h"
|
||||||
|
#include <icecream.hpp>
|
||||||
|
|
||||||
enzo::nt::GeometryConnection::GeometryConnection(enzo::nt::OpId inputOpId, unsigned int inputIndex, enzo::nt::OpId outputOpId, unsigned int outputIndex)
|
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}
|
:inputOperatorId_{inputOpId}, inputIndex_{inputIndex}, outputOperatorId_{outputOpId}, outputIndex_{outputIndex}
|
||||||
@@ -14,7 +15,11 @@ unsigned int enzo::nt::GeometryConnection::getOutputIndex() const {return output
|
|||||||
void enzo::nt::GeometryConnection::remove()
|
void enzo::nt::GeometryConnection::remove()
|
||||||
{
|
{
|
||||||
NetworkManager& nm = nt::nm();
|
NetworkManager& nm = nt::nm();
|
||||||
|
std::cout << "removing connection " << this;
|
||||||
nm.getGeoOperator(inputOperatorId_).removeOutputConnection(this);
|
nm.getGeoOperator(inputOperatorId_).removeOutputConnection(this);
|
||||||
nm.getGeoOperator(outputOperatorId_).removeInputConnection(inputIndex_);
|
nm.getGeoOperator(outputOperatorId_).removeInputConnection(inputIndex_);
|
||||||
|
removed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Engine/Types.h"
|
#include "Engine/Types.h"
|
||||||
|
#include <boost/signals2.hpp>
|
||||||
|
|
||||||
namespace enzo::nt
|
namespace enzo::nt
|
||||||
{
|
{
|
||||||
class GeometryOperator;
|
class GeometryOperator;
|
||||||
@@ -16,7 +18,12 @@ public:
|
|||||||
enzo::nt::OpId getOutputOpId() const;
|
enzo::nt::OpId getOutputOpId() const;
|
||||||
unsigned int getInputIndex() const;
|
unsigned int getInputIndex() const;
|
||||||
unsigned int getOutputIndex() const;
|
unsigned int getOutputIndex() const;
|
||||||
|
friend std::ostream& operator<<(std::ostream& os, const GeometryConnection& p)
|
||||||
|
{
|
||||||
|
return os << p.inputOperatorId_ << ":" << p.inputIndex_ << " -> " << p.outputOperatorId_ << ":" << p.outputIndex_ << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::signals2::signal<void ()> removed;
|
||||||
void remove();
|
void remove();
|
||||||
// bool isValid();
|
// bool isValid();
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "Engine/Operator/GeometryOperator.h"
|
#include "Engine/Operator/GeometryOperator.h"
|
||||||
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "Engine/Network/NetworkManager.h"
|
#include "Engine/Network/NetworkManager.h"
|
||||||
#include <optional>
|
#include <optional>
|
||||||
@@ -78,22 +79,24 @@ geo::Geometry& enzo::nt::GeometryOperator::getOutputGeo(unsigned outputIndex) co
|
|||||||
void nt::GeometryOperator::addInputConnection(std::shared_ptr<nt::GeometryConnection> newConnection)
|
void nt::GeometryOperator::addInputConnection(std::shared_ptr<nt::GeometryConnection> newConnection)
|
||||||
{
|
{
|
||||||
// delete previous input
|
// delete previous input
|
||||||
for(auto it=inputConnections_.begin(); it!=inputConnections_.end();)
|
std::shared_ptr<nt::GeometryConnection> previousConection = nullptr;
|
||||||
|
IC();
|
||||||
|
for(auto it=inputConnections_.begin(); it!=inputConnections_.end(); ++it)
|
||||||
{
|
{
|
||||||
if((*it)->getOutputIndex()==newConnection->getOutputIndex())
|
if((*it)->getOutputIndex()==newConnection->getOutputIndex())
|
||||||
{
|
{
|
||||||
inputConnections_.erase(it);
|
previousConection = *it;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
if(previousConection)
|
||||||
{
|
{
|
||||||
++it;
|
previousConection->remove();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add new newConnection
|
// add new newConnection
|
||||||
inputConnections_.push_back(newConnection);
|
inputConnections_.push_back(newConnection);
|
||||||
|
|
||||||
IC();
|
|
||||||
dirtyNode();
|
dirtyNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,11 +116,12 @@ void nt::GeometryOperator::removeInputConnection(unsigned int inputIndex)
|
|||||||
{
|
{
|
||||||
inputConnections_.erase(it);
|
inputConnections_.erase(it);
|
||||||
dirtyNode();
|
dirtyNode();
|
||||||
std::cout << "removing input connection\n";
|
std::cerr << "removing input connection\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cerr << "Couldn't remove input connection: " << inputIndex << "\n";
|
std::cerr << "Couldn't remove input connection: " << inputIndex << "\n";
|
||||||
|
IC(inputIndex, opId_, inputConnections_.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void nt::GeometryOperator::removeOutputConnection(const nt::GeometryConnection* connectionPtr)
|
void nt::GeometryOperator::removeOutputConnection(const nt::GeometryConnection* connectionPtr)
|
||||||
@@ -177,13 +181,13 @@ std::string nt::GeometryOperator::getTypeName()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::optional<const nt::GeometryConnection> nt::GeometryOperator::getInputConnection(size_t index) const
|
std::optional<std::reference_wrapper<const nt::GeometryConnection>> nt::GeometryOperator::getInputConnection(size_t index) const
|
||||||
{
|
{
|
||||||
for(auto it=inputConnections_.begin(); it!=inputConnections_.end();)
|
for(auto it=inputConnections_.begin(); it!=inputConnections_.end();)
|
||||||
{
|
{
|
||||||
if((*it)->getOutputIndex()==index)
|
if((*it)->getOutputIndex()==index)
|
||||||
{
|
{
|
||||||
return std::optional<const nt::GeometryConnection>(**it);
|
return std::cref(**it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "Engine/Operator/GeometryOpDef.h"
|
#include "Engine/Operator/GeometryOpDef.h"
|
||||||
#include "Engine/Parameter/Parameter.h"
|
#include "Engine/Parameter/Parameter.h"
|
||||||
#include "Engine/Types.h"
|
#include "Engine/Types.h"
|
||||||
|
#include <functional>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@@ -30,7 +31,7 @@ public:
|
|||||||
|
|
||||||
std::vector<std::weak_ptr<const GeometryConnection>> getInputConnections() const;
|
std::vector<std::weak_ptr<const GeometryConnection>> getInputConnections() const;
|
||||||
std::vector<std::weak_ptr<const GeometryConnection>> getOutputConnections() const;
|
std::vector<std::weak_ptr<const GeometryConnection>> getOutputConnections() const;
|
||||||
std::optional<const GeometryConnection> getInputConnection(size_t index) const;
|
std::optional<std::reference_wrapper<const GeometryConnection>> getInputConnection(size_t index) const;
|
||||||
std::vector<std::weak_ptr<prm::Parameter>> getParameters();
|
std::vector<std::weak_ptr<prm::Parameter>> getParameters();
|
||||||
std::weak_ptr<prm::Parameter> getParameter(std::string parameterName);
|
std::weak_ptr<prm::Parameter> getParameter(std::string parameterName);
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ NodeEdgeGraphic::NodeEdgeGraphic(SocketGraphic* socket1, SocketGraphic* socket2,
|
|||||||
deleteHighlightPen_.setWidth(2);
|
deleteHighlightPen_.setWidth(2);
|
||||||
updateDeleteHighlightPen();
|
updateDeleteHighlightPen();
|
||||||
|
|
||||||
|
// remove self when connection is removed
|
||||||
|
if(auto connectionShared = connection_.lock())
|
||||||
|
{
|
||||||
|
connectionShared->removed.connect([this](){ this->remove(false); });
|
||||||
|
}
|
||||||
|
|
||||||
socket1_->addEdge(this);
|
socket1_->addEdge(this);
|
||||||
socket2_->addEdge(this);
|
socket2_->addEdge(this);
|
||||||
@@ -149,7 +154,7 @@ void NodeEdgeGraphic::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeEdgeGraphic::remove()
|
void NodeEdgeGraphic::remove(bool full)
|
||||||
{
|
{
|
||||||
// TODO: possible memory leak
|
// TODO: possible memory leak
|
||||||
// these probably aren't necessary but i'm trying to fix a bug
|
// these probably aren't necessary but i'm trying to fix a bug
|
||||||
@@ -161,8 +166,11 @@ void NodeEdgeGraphic::remove()
|
|||||||
socket1_->removeEdge(this);
|
socket1_->removeEdge(this);
|
||||||
socket2_->removeEdge(this);
|
socket2_->removeEdge(this);
|
||||||
|
|
||||||
|
if(full)
|
||||||
|
{
|
||||||
if(auto connectionShared = connection_.lock())
|
if(auto connectionShared = connection_.lock())
|
||||||
{
|
{
|
||||||
connectionShared->remove();
|
connectionShared->remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public:
|
|||||||
void setPos(QPointF pos1, QPointF pos2);
|
void setPos(QPointF pos1, QPointF pos2);
|
||||||
void setStartPos(QPointF pos);
|
void setStartPos(QPointF pos);
|
||||||
void setEndPos(QPointF pos);
|
void setEndPos(QPointF pos);
|
||||||
void remove();
|
void remove(bool full=true);
|
||||||
void setDeleteHighlight(bool state);
|
void setDeleteHighlight(bool state);
|
||||||
QPen deleteHighlightPen_;
|
QPen deleteHighlightPen_;
|
||||||
QPen defaultPen_;
|
QPen defaultPen_;
|
||||||
|
|||||||
@@ -22,29 +22,28 @@ unsigned int SocketGraphic::getIndex() const
|
|||||||
|
|
||||||
void SocketGraphic::addEdge(NodeEdgeGraphic* edge)
|
void SocketGraphic::addEdge(NodeEdgeGraphic* edge)
|
||||||
{
|
{
|
||||||
std::cout << "adding edge\n";
|
// std::cout << "adding edge\n";
|
||||||
if(getIO()==enzo::nt::SocketIOType::Input && edges_.size()>0)
|
// const bool isInput = getIO()==enzo::nt::SocketIOType::Input;
|
||||||
{
|
// if(isInput && edges_.size()>0)
|
||||||
std::unordered_set<NodeEdgeGraphic*> edgesCopy = edges_;
|
// {
|
||||||
for(NodeEdgeGraphic* edge : edgesCopy)
|
// std::unordered_set<NodeEdgeGraphic*> edgesCopy = edges_;
|
||||||
{
|
// for(NodeEdgeGraphic* edge : edgesCopy)
|
||||||
if(!edge)
|
// {
|
||||||
{
|
// if(!edge)
|
||||||
continue;
|
// {
|
||||||
}
|
// continue;
|
||||||
edge->remove();
|
// }
|
||||||
}
|
// edge->remove();
|
||||||
edges_.clear();
|
// }
|
||||||
}
|
// edges_.clear();
|
||||||
|
// }
|
||||||
edges_.insert(edge);
|
edges_.insert(edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SocketGraphic::removeEdge(NodeEdgeGraphic* edge)
|
void SocketGraphic::removeEdge(NodeEdgeGraphic* edge)
|
||||||
{
|
{
|
||||||
std::cout << "removing edge\n";
|
std::cout << "removing edge\n";
|
||||||
std::cout << "before size: " << edges_.size() << "\n";
|
|
||||||
edges_.erase(edge);
|
edges_.erase(edge);
|
||||||
std::cout << "after size: " << edges_.size() << "\n";
|
|
||||||
// auto it = find(edges_.begin(), edges_.end(), edge);
|
// auto it = find(edges_.begin(), edges_.end(), edge);
|
||||||
// if(it!=edges_.end())
|
// if(it!=edges_.end())
|
||||||
// {
|
// {
|
||||||
|
|||||||
Reference in New Issue
Block a user