From 83e0977d5d25584eaa81b1a4b0945c46d7f74e5b Mon Sep 17 00:00:00 2001 From: parker Date: Wed, 30 Jul 2025 14:03:38 +0100 Subject: [PATCH] feat: variable socket counts --- src/Engine/Operator/GeometryOpDef.cpp | 36 +++++++++++++++--------- src/Engine/Operator/GeometryOpDef.h | 19 ++++++++----- src/Engine/Operator/GeometryOperator.cpp | 13 +++++---- src/Engine/Operator/GeometryOperator.h | 3 +- src/Engine/Operator/OpInfo.h | 18 ++++++++++-- src/Engine/Operator/OperatorTable.cpp | 13 +++------ src/Engine/Operator/OperatorTable.h | 4 +-- src/Gui/Network/NodeGraphic.cpp | 9 +++++- src/OpDefs/GopHouse.cpp | 4 +-- src/OpDefs/GopHouse.h | 6 ++-- src/OpDefs/GopTransform.cpp | 4 +-- src/OpDefs/GopTransform.hpp | 6 ++-- src/OpDefs/RegisterPlugin.cpp | 27 ++++++++++++------ 13 files changed, 101 insertions(+), 61 deletions(-) diff --git a/src/Engine/Operator/GeometryOpDef.cpp b/src/Engine/Operator/GeometryOpDef.cpp index 94b6759..39bf0a0 100644 --- a/src/Engine/Operator/GeometryOpDef.cpp +++ b/src/Engine/Operator/GeometryOpDef.cpp @@ -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(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(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"); } diff --git a/src/Engine/Operator/GeometryOpDef.h b/src/Engine/Operator/GeometryOpDef.h index 9ffaee9..5f93cda 100644 --- a/src/Engine/Operator/GeometryOpDef.h +++ b/src/Engine/Operator/GeometryOpDef.h @@ -3,8 +3,12 @@ #include "Engine/Operator/Context.h" #include "Engine/Types.h" #include +#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 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); } diff --git a/src/Engine/Operator/GeometryOperator.cpp b/src/Engine/Operator/GeometryOperator.cpp index aad6c99..6240f3a 100644 --- a/src/Engine/Operator/GeometryOperator.cpp +++ b/src/Engine/Operator/GeometryOperator.cpp @@ -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 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(); } diff --git a/src/Engine/Operator/GeometryOperator.h b/src/Engine/Operator/GeometryOperator.h index d9ba024..34aa500 100644 --- a/src/Engine/Operator/GeometryOperator.h +++ b/src/Engine/Operator/GeometryOperator.h @@ -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> inputConnections_; std::vector> outputConnections_; std::vector> parameters_; - unsigned int maxInputs_; - unsigned int maxOutputs_; std::unique_ptr opDef_; enzo::nt::OpId opId_; enzo::op::OpInfo opInfo_; diff --git a/src/Engine/Operator/OpInfo.h b/src/Engine/Operator/OpInfo.h index 1fea8fe..4c18740 100644 --- a/src/Engine/Operator/OpInfo.h +++ b/src/Engine/Operator/OpInfo.h @@ -1,8 +1,19 @@ #pragma once #include -#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; }; } + diff --git a/src/Engine/Operator/OperatorTable.cpp b/src/Engine/Operator/OperatorTable.cpp index a0bc157..4bc0d21 100644 --- a/src/Engine/Operator/OperatorTable.cpp +++ b/src/Engine/Operator/OperatorTable.cpp @@ -1,24 +1,19 @@ #include "Engine/Operator/OperatorTable.h" +#include "Engine/Operator/OpInfo.h" #include #include -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); } diff --git a/src/Engine/Operator/OperatorTable.h b/src/Engine/Operator/OperatorTable.h index aef66c2..dbbdf14 100644 --- a/src/Engine/Operator/OperatorTable.h +++ b/src/Engine/Operator/OperatorTable.h @@ -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 getOpInfo(std::string name); static std::vector getData(); @@ -22,6 +22,6 @@ public: private: static std::vector opInfoStore_; }; -using addOperatorPtr = void (*)(const char* internalName, const char* displayName, nt::opConstructor ctorFunc, prm::Template templateList[]); +using addOperatorPtr = void (*)(OpInfo); } diff --git a/src/Gui/Network/NodeGraphic.cpp b/src/Gui/Network/NodeGraphic.cpp index 4ad2bc5..7e25790 100644 --- a/src/Gui/Network/NodeGraphic.cpp +++ b/src/Gui/Network/NodeGraphic.cpp @@ -1,5 +1,6 @@ #include "Gui/Network/NodeGraphic.h" #include +#include #include #include #include @@ -79,11 +80,15 @@ void NodeGraphic::initFlagButtons() displayFlagButton_->setPos(QPointF(bodyRect_.right()-displayFlagButton_->getWidth()/2.0f-padding, bodyRect_.center().y())); } +#include void NodeGraphic::initSockets() { enzo::nt::GeometryOperator& op = enzo::nt::nm().getGeoOperator(opId_); + IC(); for(int i=0, max=op.getMaxInputs(); isetPos(getSocketPosition(i, enzo::nt::SocketIOType::Input)); inputs_.push_back(socketInput); @@ -91,6 +96,8 @@ void NodeGraphic::initSockets() for(int i=0, max=op.getMaxOutputs(); isetPos(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(maxSocketNumber-1))-0.5)*2*socketSpread; + xPos += ((socketIndex/static_cast(std::max(maxSocketNumber-1, 1)))-0.5)*2*socketSpread; return QPointF(xPos, yPos); } diff --git a/src/OpDefs/GopHouse.cpp b/src/OpDefs/GopHouse.cpp index beacaf5..e5c47df 100644 --- a/src/OpDefs/GopHouse.cpp +++ b/src/OpDefs/GopHouse.cpp @@ -2,8 +2,8 @@ #include "Engine/Operator/AttributeHandle.h" #include -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) { } diff --git a/src/OpDefs/GopHouse.h b/src/OpDefs/GopHouse.h index 0bfd6bd..be3dbbe 100644 --- a/src/OpDefs/GopHouse.h +++ b/src/OpDefs/GopHouse.h @@ -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[]; diff --git a/src/OpDefs/GopTransform.cpp b/src/OpDefs/GopTransform.cpp index 1113a48..c0a40f7 100644 --- a/src/OpDefs/GopTransform.cpp +++ b/src/OpDefs/GopTransform.cpp @@ -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) { } diff --git a/src/OpDefs/GopTransform.hpp b/src/OpDefs/GopTransform.hpp index 70056ff..8200a69 100644 --- a/src/OpDefs/GopTransform.hpp +++ b/src/OpDefs/GopTransform.hpp @@ -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[]; diff --git a/src/OpDefs/RegisterPlugin.cpp b/src/OpDefs/RegisterPlugin.cpp index 57dea9a..73e574a 100644 --- a/src/OpDefs/RegisterPlugin.cpp +++ b/src/OpDefs/RegisterPlugin.cpp @@ -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( - "transform", - "Transform", - &GopTransform::ctor, - GopTransform::parameterList + enzo::op::OpInfo { + "transform", + "Transform", + &GopTransform::ctor, + GopTransform::parameterList, + 1, + 1, + 1, + } ); addOperator( - "house", - "House", - &GOP_house::ctor, - GOP_house::parameterList + enzo::op::OpInfo { + "house", + "House", + &GOP_house::ctor, + GOP_house::parameterList, + 0, + 0, + 1, + } ); }