fix: remove duplicate inputs graphically
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <memory>
|
||||
#include <stack>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
enzo::nt::OpId enzo::nt::NetworkManager::addOperator(op::OpInfo opInfo)
|
||||
@@ -99,8 +100,12 @@ std::vector<enzo::nt::OpId> enzo::nt::NetworkManager::getDependencyGraph(enzo::n
|
||||
auto inputConnections = getGeoOperator(currentOp).getInputConnections();
|
||||
for(auto connection : inputConnections)
|
||||
{
|
||||
traversalBuffer.push(connection->getInputOpId());
|
||||
dependencyGraph.push_back(connection->getInputOpId());
|
||||
if(auto connectionPtr = connection.lock())
|
||||
{
|
||||
traversalBuffer.push(connectionPtr->getInputOpId());
|
||||
dependencyGraph.push_back(connectionPtr->getInputOpId());
|
||||
}
|
||||
else { throw std::runtime_error("Connection weak ptr invalid"); }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "Engine/Parameter/Parameter.h"
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
|
||||
|
||||
enzo::op::Context::Context(enzo::nt::OpId opId, enzo::nt::NetworkManager& networkManager)
|
||||
@@ -15,14 +16,21 @@ enzo::geo::Geometry enzo::op::Context::cloneInputGeo(unsigned int inputIndex)
|
||||
{
|
||||
// TODO: implement
|
||||
enzo::nt::GeometryOperator& selfOp = networkManager_.getGeoOperator(opId_);
|
||||
std::vector<std::shared_ptr<const nt::GeometryConnection>> inputConnections = selfOp.getInputConnections();
|
||||
std::vector<std::weak_ptr<const nt::GeometryConnection>> inputConnections = selfOp.getInputConnections();
|
||||
if(inputConnections.size()==0)
|
||||
{
|
||||
std::cout << "no input\n";
|
||||
return enzo::geo::Geometry();
|
||||
}
|
||||
std::shared_ptr<const nt::GeometryConnection> inputConnection = inputConnections.at(inputIndex);
|
||||
return networkManager_.getGeoOperator(inputConnection->getInputOpId()).getOutputGeo(inputConnection->getInputIndex());
|
||||
auto inputConnection = inputConnections.at(inputIndex);
|
||||
if(auto inputConnectionSP = inputConnection.lock())
|
||||
{
|
||||
return networkManager_.getGeoOperator(inputConnectionSP->getInputOpId()).getOutputGeo(inputConnectionSP->getInputIndex());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("Connection weak ptr doesn't exist");
|
||||
}
|
||||
}
|
||||
|
||||
enzo::bt::floatT enzo::op::Context::evalFloatParm(const char* parmName) const
|
||||
@@ -34,4 +42,8 @@ enzo::bt::floatT enzo::op::Context::evalFloatParm(const char* parmName) const
|
||||
{
|
||||
return sharedParm->evalFloat();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("Parameter weak ptr invalid");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,13 +70,10 @@ geo::Geometry& enzo::nt::GeometryOperator::getOutputGeo(unsigned outputIndex)
|
||||
void nt::GeometryOperator::addInputConnection(std::shared_ptr<nt::GeometryConnection> newConnection)
|
||||
{
|
||||
// delete previous input
|
||||
IC();
|
||||
for(auto it=inputConnections_.begin(); it!=inputConnections_.end();)
|
||||
{
|
||||
IC();
|
||||
if((*it)->getOutputIndex()==newConnection->getOutputIndex())
|
||||
{
|
||||
IC();
|
||||
inputConnections_.erase(it);
|
||||
}
|
||||
else
|
||||
@@ -84,7 +81,6 @@ void nt::GeometryOperator::addInputConnection(std::shared_ptr<nt::GeometryConnec
|
||||
++it;
|
||||
}
|
||||
}
|
||||
IC();
|
||||
|
||||
std::cout << "Input newConnection added\nConnecting ops " << newConnection->getInputOpId() << " -> " << newConnection->getOutputOpId() << "\n";
|
||||
std::cout << "Connecting index " << newConnection->getInputIndex() << " -> " << newConnection->getOutputIndex() << "\n";
|
||||
@@ -114,28 +110,30 @@ std::weak_ptr<prm::Parameter> nt::GeometryOperator::getParameter(std::string par
|
||||
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<const nt::GeometryConnection>> nt::GeometryOperator::getInputConnections() const
|
||||
std::vector<std::weak_ptr<const nt::GeometryConnection>> nt::GeometryOperator::getInputConnections() const
|
||||
{
|
||||
std::vector<std::shared_ptr<const nt::GeometryConnection>> inputConnections;
|
||||
for(std::shared_ptr<nt::GeometryConnection> connection : inputConnections_)
|
||||
{
|
||||
inputConnections.push_back(connection);
|
||||
}
|
||||
return inputConnections;
|
||||
return {inputConnections_.begin(), inputConnections_.end()};
|
||||
}
|
||||
std::vector<std::weak_ptr<prm::Parameter>> nt::GeometryOperator::getParameters()
|
||||
{
|
||||
return {parameters_.begin(), parameters_.end()};
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<const nt::GeometryConnection>> nt::GeometryOperator::getOutputConnections() const
|
||||
std::vector<std::weak_ptr<const nt::GeometryConnection>> nt::GeometryOperator::getOutputConnections() const
|
||||
{
|
||||
std::vector<std::shared_ptr<const nt::GeometryConnection>> outputConnections;
|
||||
for(std::shared_ptr<nt::GeometryConnection> connection : outputConnections_)
|
||||
return {outputConnections_.begin(), outputConnections_.end()};
|
||||
}
|
||||
|
||||
std::optional<const nt::GeometryConnection> nt::GeometryOperator::getInputConnection(size_t index) const
|
||||
{
|
||||
for(auto it=inputConnections_.begin(); it!=inputConnections_.end();)
|
||||
{
|
||||
outputConnections.push_back(connection);
|
||||
if((*it)->getOutputIndex()==index)
|
||||
{
|
||||
return std::optional<const nt::GeometryConnection>(**it);
|
||||
}
|
||||
}
|
||||
return outputConnections;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -24,8 +24,9 @@ public:
|
||||
|
||||
void addInputConnection(std::shared_ptr<nt::GeometryConnection> connection);
|
||||
void addOutputConnection(std::shared_ptr<nt::GeometryConnection> connection);
|
||||
std::vector<std::shared_ptr<const GeometryConnection>> getInputConnections() const;
|
||||
std::vector<std::shared_ptr<const GeometryConnection>> getOutputConnections() const;
|
||||
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;
|
||||
std::vector<std::weak_ptr<prm::Parameter>> getParameters();
|
||||
std::weak_ptr<prm::Parameter> getParameter(std::string parameterName);
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ void Network::leftMousePressed(QMouseEvent *event)
|
||||
void Network::socketClicked(SocketGraphic* socket, QMouseEvent *event)
|
||||
{
|
||||
std::cout << "socket clicked\n";
|
||||
// if first click
|
||||
// clicked first socket
|
||||
if(!floatingEdge_)
|
||||
{
|
||||
startSocket_=socket;
|
||||
@@ -138,7 +138,7 @@ void Network::socketClicked(SocketGraphic* socket, QMouseEvent *event)
|
||||
scene_->addItem(floatingEdge_);
|
||||
floatingEdge_->setFloatPos(view_->mapToScene(event->pos()));
|
||||
}
|
||||
// second click
|
||||
// clicked second socket
|
||||
// connect to opposite type
|
||||
else if (
|
||||
socket->getIO()!=startSocket_->getIO() &&
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <qgraphicsitem.h>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneHoverEvent>
|
||||
#include "icecream.hpp"
|
||||
|
||||
NodeEdgeGraphic::NodeEdgeGraphic(SocketGraphic* socket1, SocketGraphic* socket2, QGraphicsItem *parent)
|
||||
: QGraphicsItem(parent), socket1_{socket1}, socket2_{socket2}, defaultColor_{QColor("white")}
|
||||
@@ -150,6 +151,7 @@ void NodeEdgeGraphic::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
|
||||
|
||||
void NodeEdgeGraphic::cleanUp()
|
||||
{
|
||||
// TODO: possible memory leak
|
||||
// these probably aren't necessary but i'm trying to fix a bug
|
||||
prepareGeometryChange();
|
||||
update();
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <iostream>
|
||||
#include <qgraphicsitem.h>
|
||||
#include "Gui/Network/NodeEdgeGraphic.h"
|
||||
#include "icecream.hpp"
|
||||
|
||||
SocketGraphic::SocketGraphic(enzo::nt::SocketIOType type, enzo::nt::OpId opId, unsigned int socketIndex, QGraphicsItem *parent)
|
||||
: QGraphicsItem(parent), type_{type}, opId_{opId}, socketIndex_{socketIndex}
|
||||
@@ -22,6 +23,19 @@ unsigned int SocketGraphic::getIndex() const
|
||||
void SocketGraphic::addEdge(NodeEdgeGraphic* edge)
|
||||
{
|
||||
std::cout << "adding edge\n";
|
||||
if(getIO()==enzo::nt::SocketIOType::Input && edges_.size()>0)
|
||||
{
|
||||
std::unordered_set<NodeEdgeGraphic*> edgesCopy = edges_;
|
||||
for(NodeEdgeGraphic* edge : edgesCopy)
|
||||
{
|
||||
if(!edge)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
edge->cleanUp();
|
||||
}
|
||||
edges_.clear();
|
||||
}
|
||||
edges_.insert(edge);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user