fix: remove duplicate inputs graphically
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
enzo::nt::OpId enzo::nt::NetworkManager::addOperator(op::OpInfo opInfo)
|
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();
|
auto inputConnections = getGeoOperator(currentOp).getInputConnections();
|
||||||
for(auto connection : inputConnections)
|
for(auto connection : inputConnections)
|
||||||
{
|
{
|
||||||
traversalBuffer.push(connection->getInputOpId());
|
if(auto connectionPtr = connection.lock())
|
||||||
dependencyGraph.push_back(connection->getInputOpId());
|
{
|
||||||
|
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 "Engine/Parameter/Parameter.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
|
||||||
enzo::op::Context::Context(enzo::nt::OpId opId, enzo::nt::NetworkManager& networkManager)
|
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
|
// TODO: implement
|
||||||
enzo::nt::GeometryOperator& selfOp = networkManager_.getGeoOperator(opId_);
|
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)
|
if(inputConnections.size()==0)
|
||||||
{
|
{
|
||||||
std::cout << "no input\n";
|
std::cout << "no input\n";
|
||||||
return enzo::geo::Geometry();
|
return enzo::geo::Geometry();
|
||||||
}
|
}
|
||||||
std::shared_ptr<const nt::GeometryConnection> inputConnection = inputConnections.at(inputIndex);
|
auto inputConnection = inputConnections.at(inputIndex);
|
||||||
return networkManager_.getGeoOperator(inputConnection->getInputOpId()).getOutputGeo(inputConnection->getInputIndex());
|
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
|
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();
|
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)
|
void nt::GeometryOperator::addInputConnection(std::shared_ptr<nt::GeometryConnection> newConnection)
|
||||||
{
|
{
|
||||||
// delete previous input
|
// delete previous input
|
||||||
IC();
|
|
||||||
for(auto it=inputConnections_.begin(); it!=inputConnections_.end();)
|
for(auto it=inputConnections_.begin(); it!=inputConnections_.end();)
|
||||||
{
|
{
|
||||||
IC();
|
|
||||||
if((*it)->getOutputIndex()==newConnection->getOutputIndex())
|
if((*it)->getOutputIndex()==newConnection->getOutputIndex())
|
||||||
{
|
{
|
||||||
IC();
|
|
||||||
inputConnections_.erase(it);
|
inputConnections_.erase(it);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -84,7 +81,6 @@ void nt::GeometryOperator::addInputConnection(std::shared_ptr<nt::GeometryConnec
|
|||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IC();
|
|
||||||
|
|
||||||
std::cout << "Input newConnection added\nConnecting ops " << newConnection->getInputOpId() << " -> " << newConnection->getOutputOpId() << "\n";
|
std::cout << "Input newConnection added\nConnecting ops " << newConnection->getInputOpId() << " -> " << newConnection->getOutputOpId() << "\n";
|
||||||
std::cout << "Connecting index " << newConnection->getInputIndex() << " -> " << newConnection->getOutputIndex() << "\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;
|
return {inputConnections_.begin(), inputConnections_.end()};
|
||||||
for(std::shared_ptr<nt::GeometryConnection> connection : inputConnections_)
|
|
||||||
{
|
|
||||||
inputConnections.push_back(connection);
|
|
||||||
}
|
|
||||||
return inputConnections;
|
|
||||||
}
|
}
|
||||||
std::vector<std::weak_ptr<prm::Parameter>> nt::GeometryOperator::getParameters()
|
std::vector<std::weak_ptr<prm::Parameter>> nt::GeometryOperator::getParameters()
|
||||||
{
|
{
|
||||||
return {parameters_.begin(), parameters_.end()};
|
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;
|
return {outputConnections_.begin(), outputConnections_.end()};
|
||||||
for(std::shared_ptr<nt::GeometryConnection> connection : outputConnections_)
|
}
|
||||||
|
|
||||||
|
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 addInputConnection(std::shared_ptr<nt::GeometryConnection> connection);
|
||||||
void addOutputConnection(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::weak_ptr<const GeometryConnection>> getInputConnections() const;
|
||||||
std::vector<std::shared_ptr<const GeometryConnection>> getOutputConnections() 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::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);
|
||||||
|
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ void Network::leftMousePressed(QMouseEvent *event)
|
|||||||
void Network::socketClicked(SocketGraphic* socket, QMouseEvent *event)
|
void Network::socketClicked(SocketGraphic* socket, QMouseEvent *event)
|
||||||
{
|
{
|
||||||
std::cout << "socket clicked\n";
|
std::cout << "socket clicked\n";
|
||||||
// if first click
|
// clicked first socket
|
||||||
if(!floatingEdge_)
|
if(!floatingEdge_)
|
||||||
{
|
{
|
||||||
startSocket_=socket;
|
startSocket_=socket;
|
||||||
@@ -138,7 +138,7 @@ void Network::socketClicked(SocketGraphic* socket, QMouseEvent *event)
|
|||||||
scene_->addItem(floatingEdge_);
|
scene_->addItem(floatingEdge_);
|
||||||
floatingEdge_->setFloatPos(view_->mapToScene(event->pos()));
|
floatingEdge_->setFloatPos(view_->mapToScene(event->pos()));
|
||||||
}
|
}
|
||||||
// second click
|
// clicked second socket
|
||||||
// connect to opposite type
|
// connect to opposite type
|
||||||
else if (
|
else if (
|
||||||
socket->getIO()!=startSocket_->getIO() &&
|
socket->getIO()!=startSocket_->getIO() &&
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <qgraphicsitem.h>
|
#include <qgraphicsitem.h>
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
#include <QGraphicsSceneHoverEvent>
|
#include <QGraphicsSceneHoverEvent>
|
||||||
|
#include "icecream.hpp"
|
||||||
|
|
||||||
NodeEdgeGraphic::NodeEdgeGraphic(SocketGraphic* socket1, SocketGraphic* socket2, QGraphicsItem *parent)
|
NodeEdgeGraphic::NodeEdgeGraphic(SocketGraphic* socket1, SocketGraphic* socket2, QGraphicsItem *parent)
|
||||||
: QGraphicsItem(parent), socket1_{socket1}, socket2_{socket2}, defaultColor_{QColor("white")}
|
: QGraphicsItem(parent), socket1_{socket1}, socket2_{socket2}, defaultColor_{QColor("white")}
|
||||||
@@ -150,6 +151,7 @@ void NodeEdgeGraphic::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
|
|||||||
|
|
||||||
void NodeEdgeGraphic::cleanUp()
|
void NodeEdgeGraphic::cleanUp()
|
||||||
{
|
{
|
||||||
|
// 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
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
update();
|
update();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <qgraphicsitem.h>
|
#include <qgraphicsitem.h>
|
||||||
#include "Gui/Network/NodeEdgeGraphic.h"
|
#include "Gui/Network/NodeEdgeGraphic.h"
|
||||||
|
#include "icecream.hpp"
|
||||||
|
|
||||||
SocketGraphic::SocketGraphic(enzo::nt::SocketIOType type, enzo::nt::OpId opId, unsigned int socketIndex, QGraphicsItem *parent)
|
SocketGraphic::SocketGraphic(enzo::nt::SocketIOType type, enzo::nt::OpId opId, unsigned int socketIndex, QGraphicsItem *parent)
|
||||||
: QGraphicsItem(parent), type_{type}, opId_{opId}, socketIndex_{socketIndex}
|
: QGraphicsItem(parent), type_{type}, opId_{opId}, socketIndex_{socketIndex}
|
||||||
@@ -22,6 +23,19 @@ 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)
|
||||||
|
{
|
||||||
|
std::unordered_set<NodeEdgeGraphic*> edgesCopy = edges_;
|
||||||
|
for(NodeEdgeGraphic* edge : edgesCopy)
|
||||||
|
{
|
||||||
|
if(!edge)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
edge->cleanUp();
|
||||||
|
}
|
||||||
|
edges_.clear();
|
||||||
|
}
|
||||||
edges_.insert(edge);
|
edges_.insert(edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user