feat: variable socket counts

This commit is contained in:
parker
2025-07-30 14:03:38 +01:00
parent 1c57b7a9e6
commit 83e0977d5d
13 changed files with 101 additions and 61 deletions

View File

@@ -13,35 +13,43 @@ bool enzo::nt::GeometryOpDef::outputRequested(unsigned int outputIndex)
return true;
}
const enzo::geo::Geometry& enzo::nt::GeometryOpDef::getInputGeoView(unsigned int inputIndex)
{
// TODO: implement
return enzo::geo::Geometry();
}
void enzo::nt::GeometryOpDef::setOutputGeometry(unsigned int outputIndex, enzo::geo::Geometry geometry)
{
if(outputIndex>maxOutputs_)
if(outputIndex>getMaxOutputs())
{
throw std::runtime_error("Cannot set output geometry to index > maxOutputs");
}
outputGeometry_[outputIndex] = geometry;
}
enzo::nt::GeometryOpDef::GeometryOpDef(enzo::nt::OpId opId)
: opId_{opId}
unsigned int enzo::nt::GeometryOpDef::getMinInputs() const
{
minInputs_=1;
maxInputs_=4;
maxOutputs_=4;
outputGeometry_ = std::vector<enzo::geo::Geometry>(4, enzo::geo::Geometry());
return opInfo_.minInputs;
}
unsigned int enzo::nt::GeometryOpDef::getMaxInputs() const
{
return opInfo_.maxInputs;
}
unsigned int enzo::nt::GeometryOpDef::getMaxOutputs() const
{
return opInfo_.maxOutputs;
}
enzo::nt::GeometryOpDef::GeometryOpDef(nt::NetworkManager* network, op::OpInfo opInfo)
: opInfo_{opInfo}, network_{network}
{
outputGeometry_ = std::vector<enzo::geo::Geometry>(getMaxOutputs(), enzo::geo::Geometry());
}
enzo::geo::Geometry& enzo::nt::GeometryOpDef::getOutputGeo(unsigned outputIndex)
{
if(outputIndex>maxOutputs_)
if(outputIndex>getMaxOutputs())
{
throw std::runtime_error("Cannot set output geometry to index > maxOutputs");
}

View File

@@ -3,8 +3,12 @@
#include "Engine/Operator/Context.h"
#include "Engine/Types.h"
#include <boost/config.hpp>
#include "Engine/Operator/OpInfo.h"
// forward declaration
namespace enzo::nt {class NetworkManager;}
namespace enzo::nt
{
class NetworkManager;
@@ -12,24 +16,25 @@ class NetworkManager;
class BOOST_SYMBOL_EXPORT GeometryOpDef
{
public:
GeometryOpDef(enzo::nt::OpId opId);
GeometryOpDef(nt::NetworkManager* network, op::OpInfo opInfo);
virtual void cookOp(op::Context context) = 0;
geo::Geometry& getOutputGeo(unsigned outputIndex);
unsigned int getMinInputs() const;
unsigned int getMaxInputs() const;
unsigned int getMaxOutputs() const;
private:
std::vector<enzo::geo::Geometry> outputGeometry_;
unsigned int minInputs_;
unsigned int maxInputs_;
unsigned int maxOutputs_;
protected:
enzo::nt::OpId opId_;
const enzo::geo::Geometry& getInputGeoView(unsigned int inputIndex);
const op::OpInfo opInfo_;
nt::NetworkManager* network_;
bool outputRequested(unsigned int outputIndex);
// TODO: std::move geometry instead of copying
void setOutputGeometry(unsigned int outputIndex, enzo::geo::Geometry geometry);
};
using opConstructor = GeometryOpDef* (*)(enzo::nt::OpId);
using opConstructor = GeometryOpDef* (*)(enzo::nt::NetworkManager* network, enzo::op::OpInfo opInfo);
}

View File

@@ -27,11 +27,8 @@ void enzo::nt::connectOperators(enzo::nt::OpId inputOpId, unsigned int inputInde
}
nt::GeometryOperator::GeometryOperator(enzo::nt::OpId opId, op::OpInfo opInfo)
: opId_{opId}, opInfo_{opInfo}, opDef_(opInfo.ctorFunc(opId))
: opId_{opId}, opInfo_{opInfo}, opDef_(opInfo.ctorFunc(&nt::nm(), opInfo))
{
// TODO: drive by geometry definition
maxInputs_=4;
maxOutputs_=4;
initParameters();
}
@@ -165,9 +162,13 @@ std::optional<const nt::GeometryConnection> nt::GeometryOperator::getInputConnec
unsigned int nt::GeometryOperator::getMaxInputs() const
{
return maxInputs_;
return opDef_->getMaxInputs();
}
unsigned int nt::GeometryOperator::getMaxOutputs() const
{
return maxOutputs_;
return opDef_->getMaxOutputs();
}
unsigned int nt::GeometryOperator::getMinInputs() const
{
return opDef_->getMinInputs();
}

View File

@@ -36,6 +36,7 @@ public:
unsigned int getMaxInputs() const;
unsigned int getMinInputs() const;
unsigned int getMaxOutputs() const;
// signals
@@ -50,8 +51,6 @@ private:
std::vector<std::shared_ptr<nt::GeometryConnection>> inputConnections_;
std::vector<std::shared_ptr<nt::GeometryConnection>> outputConnections_;
std::vector<std::shared_ptr<prm::Parameter>> parameters_;
unsigned int maxInputs_;
unsigned int maxOutputs_;
std::unique_ptr<enzo::nt::GeometryOpDef> opDef_;
enzo::nt::OpId opId_;
enzo::op::OpInfo opInfo_;

View File

@@ -1,8 +1,19 @@
#pragma once
#include <string>
#include "Engine/Operator/GeometryOpDef.h"
#include "Engine/Parameter/Template.h"
// forward declaration
namespace enzo::op
{
struct OpInfo;
}
namespace enzo::nt
{
class GeometryOpDef;
class NetworkManager;
using opConstructor = GeometryOpDef* (*)(enzo::nt::NetworkManager* network, enzo::op::OpInfo opInfo);
}
namespace enzo::op
{
struct OpInfo
@@ -11,6 +22,9 @@ struct OpInfo
std::string displayName;
enzo::nt::opConstructor ctorFunc;
enzo::prm::Template* templates;
size_t templatesSize;
unsigned int minInputs=0;
unsigned int maxInputs=1;
unsigned int maxOutputs=1;
};
}

View File

@@ -1,24 +1,19 @@
#include "Engine/Operator/OperatorTable.h"
#include "Engine/Operator/OpInfo.h"
#include <boost/dll/import.hpp>
#include <iostream>
void enzo::op::OperatorTable::addOperator(const char* internalName, const char* displayName, nt::opConstructor ctorFunc, prm::Template templates[])
void enzo::op::OperatorTable::addOperator(enzo::op::OpInfo info)
{
std::cout << "OPERATOR TABLE ADDED\n";
std::cout << "adding operator: " << displayName << "\n";
std::cout << "adding operator: " << info.displayName << "\n";
for(const prm::Template* t = templates; t->isValid(); ++t)
for(const prm::Template* t = info.templates; t->isValid(); ++t)
{
std::cout << "name: " << t->getName() << "\n";
}
enzo::op::OpInfo info {
internalName,
displayName,
ctorFunc,
templates,
};
opInfoStore_.push_back(info);
}

View File

@@ -13,7 +13,7 @@ namespace enzo::op
class BOOST_SYMBOL_EXPORT OperatorTable
{
public:
static void addOperator(const char* internalName, const char* displayName, nt::opConstructor ctorFunc, prm::Template templates[]);
static void addOperator(enzo::op::OpInfo info);
static nt::opConstructor getOpConstructor(std::string name);
static const std::optional<op::OpInfo> getOpInfo(std::string name);
static std::vector<OpInfo> getData();
@@ -22,6 +22,6 @@ public:
private:
static std::vector<OpInfo> opInfoStore_;
};
using addOperatorPtr = void (*)(const char* internalName, const char* displayName, nt::opConstructor ctorFunc, prm::Template templateList[]);
using addOperatorPtr = void (*)(OpInfo);
}

View File

@@ -1,5 +1,6 @@
#include "Gui/Network/NodeGraphic.h"
#include <QTextDocument>
#include <algorithm>
#include <iostream>
#include <qgraphicsitem.h>
#include <qnamespace.h>
@@ -79,11 +80,15 @@ void NodeGraphic::initFlagButtons()
displayFlagButton_->setPos(QPointF(bodyRect_.right()-displayFlagButton_->getWidth()/2.0f-padding, bodyRect_.center().y()));
}
#include <icecream.hpp>
void NodeGraphic::initSockets()
{
enzo::nt::GeometryOperator& op = enzo::nt::nm().getGeoOperator(opId_);
IC();
for(int i=0, max=op.getMaxInputs(); i<max; ++i)
{
IC();
std::cout << "CREATING INPUT SOCKET!\n";
auto* socketInput = new SocketGraphic(enzo::nt::SocketIOType::Input, opId_, i, this);
socketInput->setPos(getSocketPosition(i, enzo::nt::SocketIOType::Input));
inputs_.push_back(socketInput);
@@ -91,6 +96,8 @@ void NodeGraphic::initSockets()
for(int i=0, max=op.getMaxOutputs(); i<max; ++i)
{
IC();
std::cout << "CREATING OUTPUT SOCKET!\n";
auto* socketOutput = new SocketGraphic(enzo::nt::SocketIOType::Output, opId_, i, this);
socketOutput->setPos(getSocketPosition(i, enzo::nt::SocketIOType::Output));
outputs_.push_back(socketOutput);
@@ -212,7 +219,7 @@ QPointF NodeGraphic::getSocketPosition(int socketIndex, enzo::nt::SocketIOType s
xPos = bodyRect_.center().x();
yPos = socketType == enzo::nt::SocketIOType::Input ? bodyRect_.top() : bodyRect_.bottom();
xPos += ((socketIndex/static_cast<float>(maxSocketNumber-1))-0.5)*2*socketSpread;
xPos += ((socketIndex/static_cast<float>(std::max(maxSocketNumber-1, 1)))-0.5)*2*socketSpread;
return QPointF(xPos, yPos);
}

View File

@@ -2,8 +2,8 @@
#include "Engine/Operator/AttributeHandle.h"
#include <oneapi/tbb/parallel_for.h>
GOP_house::GOP_house(enzo::nt::OpId opId)
: enzo::nt::GeometryOpDef(opId)
GOP_house::GOP_house(enzo::nt::NetworkManager* network, enzo::op::OpInfo opInfo)
: GeometryOpDef(network, opInfo)
{
}

View File

@@ -6,11 +6,11 @@ class GOP_house
: public enzo::nt::GeometryOpDef
{
public:
GOP_house(enzo::nt::OpId opId);
GOP_house(enzo::nt::NetworkManager* network, enzo::op::OpInfo opInfo);
virtual void cookOp(enzo::op::Context context);
static enzo::nt::GeometryOpDef* ctor(enzo::nt::OpId opId)
static enzo::nt::GeometryOpDef* ctor(enzo::nt::NetworkManager* network, enzo::op::OpInfo opInfo)
{
return new GOP_house(opId);
return new GOP_house(network, opInfo);
}
static BOOST_SYMBOL_EXPORT enzo::prm::Template parameterList[];

View File

@@ -2,8 +2,8 @@
#include "Engine/Operator/AttributeHandle.h"
#include "Engine/Parameter/Template.h"
GopTransform::GopTransform(enzo::nt::OpId opId)
: enzo::nt::GeometryOpDef(opId)
GopTransform::GopTransform(enzo::nt::NetworkManager* network, enzo::op::OpInfo opInfo)
: GeometryOpDef(network, opInfo)
{
}

View File

@@ -6,11 +6,11 @@ class GopTransform
: public enzo::nt::GeometryOpDef
{
public:
GopTransform(enzo::nt::OpId opId);
GopTransform(enzo::nt::NetworkManager* network, enzo::op::OpInfo opInfo);
virtual void cookOp(enzo::op::Context context);
static enzo::nt::GeometryOpDef* ctor(enzo::nt::OpId opId)
static enzo::nt::GeometryOpDef* ctor(enzo::nt::NetworkManager* network, enzo::op::OpInfo opInfo)
{
return new GopTransform(opId);
return new GopTransform(network, opInfo);
}
static BOOST_SYMBOL_EXPORT enzo::prm::Template parameterList[];

View File

@@ -1,3 +1,4 @@
#include "Engine/Operator/OpInfo.h"
#include "Engine/Operator/OperatorTable.h"
#include "GopHouse.h"
#include "OpDefs/GopTransform.hpp"
@@ -9,16 +10,26 @@ extern "C"
BOOST_SYMBOL_EXPORT void newSopOperator(enzo::op::addOperatorPtr addOperator)
{
addOperator(
enzo::op::OpInfo {
"transform",
"Transform",
&GopTransform::ctor,
GopTransform::parameterList
GopTransform::parameterList,
1,
1,
1,
}
);
addOperator(
enzo::op::OpInfo {
"house",
"House",
&GOP_house::ctor,
GOP_house::parameterList
GOP_house::parameterList,
0,
0,
1,
}
);
}