feat: variable socket counts
This commit is contained in:
@@ -13,35 +13,43 @@ bool enzo::nt::GeometryOpDef::outputRequested(unsigned int outputIndex)
|
|||||||
return true;
|
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)
|
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");
|
throw std::runtime_error("Cannot set output geometry to index > maxOutputs");
|
||||||
}
|
}
|
||||||
outputGeometry_[outputIndex] = geometry;
|
outputGeometry_[outputIndex] = geometry;
|
||||||
}
|
}
|
||||||
|
|
||||||
enzo::nt::GeometryOpDef::GeometryOpDef(enzo::nt::OpId opId)
|
unsigned int enzo::nt::GeometryOpDef::getMinInputs() const
|
||||||
: opId_{opId}
|
|
||||||
{
|
{
|
||||||
minInputs_=1;
|
return opInfo_.minInputs;
|
||||||
maxInputs_=4;
|
|
||||||
maxOutputs_=4;
|
}
|
||||||
outputGeometry_ = std::vector<enzo::geo::Geometry>(4, enzo::geo::Geometry());
|
|
||||||
|
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)
|
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");
|
throw std::runtime_error("Cannot set output geometry to index > maxOutputs");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,12 @@
|
|||||||
#include "Engine/Operator/Context.h"
|
#include "Engine/Operator/Context.h"
|
||||||
#include "Engine/Types.h"
|
#include "Engine/Types.h"
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
|
#include "Engine/Operator/OpInfo.h"
|
||||||
|
|
||||||
|
|
||||||
|
// forward declaration
|
||||||
|
namespace enzo::nt {class NetworkManager;}
|
||||||
|
|
||||||
namespace enzo::nt
|
namespace enzo::nt
|
||||||
{
|
{
|
||||||
class NetworkManager;
|
class NetworkManager;
|
||||||
@@ -12,24 +16,25 @@ class NetworkManager;
|
|||||||
class BOOST_SYMBOL_EXPORT GeometryOpDef
|
class BOOST_SYMBOL_EXPORT GeometryOpDef
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GeometryOpDef(enzo::nt::OpId opId);
|
GeometryOpDef(nt::NetworkManager* network, op::OpInfo opInfo);
|
||||||
virtual void cookOp(op::Context context) = 0;
|
virtual void cookOp(op::Context context) = 0;
|
||||||
geo::Geometry& getOutputGeo(unsigned outputIndex);
|
geo::Geometry& getOutputGeo(unsigned outputIndex);
|
||||||
|
|
||||||
|
unsigned int getMinInputs() const;
|
||||||
|
unsigned int getMaxInputs() const;
|
||||||
|
unsigned int getMaxOutputs() const;
|
||||||
private:
|
private:
|
||||||
std::vector<enzo::geo::Geometry> outputGeometry_;
|
std::vector<enzo::geo::Geometry> outputGeometry_;
|
||||||
unsigned int minInputs_;
|
|
||||||
unsigned int maxInputs_;
|
|
||||||
unsigned int maxOutputs_;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
enzo::nt::OpId opId_;
|
const op::OpInfo opInfo_;
|
||||||
const enzo::geo::Geometry& getInputGeoView(unsigned int inputIndex);
|
nt::NetworkManager* network_;
|
||||||
bool outputRequested(unsigned int outputIndex);
|
bool outputRequested(unsigned int outputIndex);
|
||||||
|
|
||||||
// TODO: std::move geometry instead of copying
|
// TODO: std::move geometry instead of copying
|
||||||
void setOutputGeometry(unsigned int outputIndex, enzo::geo::Geometry geometry);
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
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();
|
initParameters();
|
||||||
}
|
}
|
||||||
@@ -165,9 +162,13 @@ std::optional<const nt::GeometryConnection> nt::GeometryOperator::getInputConnec
|
|||||||
|
|
||||||
unsigned int nt::GeometryOperator::getMaxInputs() const
|
unsigned int nt::GeometryOperator::getMaxInputs() const
|
||||||
{
|
{
|
||||||
return maxInputs_;
|
return opDef_->getMaxInputs();
|
||||||
}
|
}
|
||||||
unsigned int nt::GeometryOperator::getMaxOutputs() const
|
unsigned int nt::GeometryOperator::getMaxOutputs() const
|
||||||
{
|
{
|
||||||
return maxOutputs_;
|
return opDef_->getMaxOutputs();
|
||||||
|
}
|
||||||
|
unsigned int nt::GeometryOperator::getMinInputs() const
|
||||||
|
{
|
||||||
|
return opDef_->getMinInputs();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
unsigned int getMaxInputs() const;
|
unsigned int getMaxInputs() const;
|
||||||
|
unsigned int getMinInputs() const;
|
||||||
unsigned int getMaxOutputs() const;
|
unsigned int getMaxOutputs() const;
|
||||||
|
|
||||||
// signals
|
// signals
|
||||||
@@ -50,8 +51,6 @@ private:
|
|||||||
std::vector<std::shared_ptr<nt::GeometryConnection>> inputConnections_;
|
std::vector<std::shared_ptr<nt::GeometryConnection>> inputConnections_;
|
||||||
std::vector<std::shared_ptr<nt::GeometryConnection>> outputConnections_;
|
std::vector<std::shared_ptr<nt::GeometryConnection>> outputConnections_;
|
||||||
std::vector<std::shared_ptr<prm::Parameter>> parameters_;
|
std::vector<std::shared_ptr<prm::Parameter>> parameters_;
|
||||||
unsigned int maxInputs_;
|
|
||||||
unsigned int maxOutputs_;
|
|
||||||
std::unique_ptr<enzo::nt::GeometryOpDef> opDef_;
|
std::unique_ptr<enzo::nt::GeometryOpDef> opDef_;
|
||||||
enzo::nt::OpId opId_;
|
enzo::nt::OpId opId_;
|
||||||
enzo::op::OpInfo opInfo_;
|
enzo::op::OpInfo opInfo_;
|
||||||
|
|||||||
@@ -1,8 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Engine/Operator/GeometryOpDef.h"
|
|
||||||
#include "Engine/Parameter/Template.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
|
namespace enzo::op
|
||||||
{
|
{
|
||||||
struct OpInfo
|
struct OpInfo
|
||||||
@@ -11,6 +22,9 @@ struct OpInfo
|
|||||||
std::string displayName;
|
std::string displayName;
|
||||||
enzo::nt::opConstructor ctorFunc;
|
enzo::nt::opConstructor ctorFunc;
|
||||||
enzo::prm::Template* templates;
|
enzo::prm::Template* templates;
|
||||||
size_t templatesSize;
|
unsigned int minInputs=0;
|
||||||
|
unsigned int maxInputs=1;
|
||||||
|
unsigned int maxOutputs=1;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,19 @@
|
|||||||
#include "Engine/Operator/OperatorTable.h"
|
#include "Engine/Operator/OperatorTable.h"
|
||||||
|
#include "Engine/Operator/OpInfo.h"
|
||||||
#include <boost/dll/import.hpp>
|
#include <boost/dll/import.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#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 << "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";
|
std::cout << "name: " << t->getName() << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
enzo::op::OpInfo info {
|
|
||||||
internalName,
|
|
||||||
displayName,
|
|
||||||
ctorFunc,
|
|
||||||
templates,
|
|
||||||
};
|
|
||||||
|
|
||||||
opInfoStore_.push_back(info);
|
opInfoStore_.push_back(info);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace enzo::op
|
|||||||
class BOOST_SYMBOL_EXPORT OperatorTable
|
class BOOST_SYMBOL_EXPORT OperatorTable
|
||||||
{
|
{
|
||||||
public:
|
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 nt::opConstructor getOpConstructor(std::string name);
|
||||||
static const std::optional<op::OpInfo> getOpInfo(std::string name);
|
static const std::optional<op::OpInfo> getOpInfo(std::string name);
|
||||||
static std::vector<OpInfo> getData();
|
static std::vector<OpInfo> getData();
|
||||||
@@ -22,6 +22,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
static std::vector<OpInfo> opInfoStore_;
|
static std::vector<OpInfo> opInfoStore_;
|
||||||
};
|
};
|
||||||
using addOperatorPtr = void (*)(const char* internalName, const char* displayName, nt::opConstructor ctorFunc, prm::Template templateList[]);
|
using addOperatorPtr = void (*)(OpInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "Gui/Network/NodeGraphic.h"
|
#include "Gui/Network/NodeGraphic.h"
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <qgraphicsitem.h>
|
#include <qgraphicsitem.h>
|
||||||
#include <qnamespace.h>
|
#include <qnamespace.h>
|
||||||
@@ -79,11 +80,15 @@ void NodeGraphic::initFlagButtons()
|
|||||||
displayFlagButton_->setPos(QPointF(bodyRect_.right()-displayFlagButton_->getWidth()/2.0f-padding, bodyRect_.center().y()));
|
displayFlagButton_->setPos(QPointF(bodyRect_.right()-displayFlagButton_->getWidth()/2.0f-padding, bodyRect_.center().y()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <icecream.hpp>
|
||||||
void NodeGraphic::initSockets()
|
void NodeGraphic::initSockets()
|
||||||
{
|
{
|
||||||
enzo::nt::GeometryOperator& op = enzo::nt::nm().getGeoOperator(opId_);
|
enzo::nt::GeometryOperator& op = enzo::nt::nm().getGeoOperator(opId_);
|
||||||
|
IC();
|
||||||
for(int i=0, max=op.getMaxInputs(); i<max; ++i)
|
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);
|
auto* socketInput = new SocketGraphic(enzo::nt::SocketIOType::Input, opId_, i, this);
|
||||||
socketInput->setPos(getSocketPosition(i, enzo::nt::SocketIOType::Input));
|
socketInput->setPos(getSocketPosition(i, enzo::nt::SocketIOType::Input));
|
||||||
inputs_.push_back(socketInput);
|
inputs_.push_back(socketInput);
|
||||||
@@ -91,6 +96,8 @@ void NodeGraphic::initSockets()
|
|||||||
|
|
||||||
for(int i=0, max=op.getMaxOutputs(); i<max; ++i)
|
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);
|
auto* socketOutput = new SocketGraphic(enzo::nt::SocketIOType::Output, opId_, i, this);
|
||||||
socketOutput->setPos(getSocketPosition(i, enzo::nt::SocketIOType::Output));
|
socketOutput->setPos(getSocketPosition(i, enzo::nt::SocketIOType::Output));
|
||||||
outputs_.push_back(socketOutput);
|
outputs_.push_back(socketOutput);
|
||||||
@@ -212,7 +219,7 @@ QPointF NodeGraphic::getSocketPosition(int socketIndex, enzo::nt::SocketIOType s
|
|||||||
xPos = bodyRect_.center().x();
|
xPos = bodyRect_.center().x();
|
||||||
yPos = socketType == enzo::nt::SocketIOType::Input ? bodyRect_.top() : bodyRect_.bottom();
|
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);
|
return QPointF(xPos, yPos);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
#include "Engine/Operator/AttributeHandle.h"
|
#include "Engine/Operator/AttributeHandle.h"
|
||||||
#include <oneapi/tbb/parallel_for.h>
|
#include <oneapi/tbb/parallel_for.h>
|
||||||
|
|
||||||
GOP_house::GOP_house(enzo::nt::OpId opId)
|
GOP_house::GOP_house(enzo::nt::NetworkManager* network, enzo::op::OpInfo opInfo)
|
||||||
: enzo::nt::GeometryOpDef(opId)
|
: GeometryOpDef(network, opInfo)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ class GOP_house
|
|||||||
: public enzo::nt::GeometryOpDef
|
: public enzo::nt::GeometryOpDef
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GOP_house(enzo::nt::OpId opId);
|
GOP_house(enzo::nt::NetworkManager* network, enzo::op::OpInfo opInfo);
|
||||||
virtual void cookOp(enzo::op::Context context);
|
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[];
|
static BOOST_SYMBOL_EXPORT enzo::prm::Template parameterList[];
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
#include "Engine/Operator/AttributeHandle.h"
|
#include "Engine/Operator/AttributeHandle.h"
|
||||||
#include "Engine/Parameter/Template.h"
|
#include "Engine/Parameter/Template.h"
|
||||||
|
|
||||||
GopTransform::GopTransform(enzo::nt::OpId opId)
|
GopTransform::GopTransform(enzo::nt::NetworkManager* network, enzo::op::OpInfo opInfo)
|
||||||
: enzo::nt::GeometryOpDef(opId)
|
: GeometryOpDef(network, opInfo)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ class GopTransform
|
|||||||
: public enzo::nt::GeometryOpDef
|
: public enzo::nt::GeometryOpDef
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GopTransform(enzo::nt::OpId opId);
|
GopTransform(enzo::nt::NetworkManager* network, enzo::op::OpInfo opInfo);
|
||||||
virtual void cookOp(enzo::op::Context context);
|
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[];
|
static BOOST_SYMBOL_EXPORT enzo::prm::Template parameterList[];
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include "Engine/Operator/OpInfo.h"
|
||||||
#include "Engine/Operator/OperatorTable.h"
|
#include "Engine/Operator/OperatorTable.h"
|
||||||
#include "GopHouse.h"
|
#include "GopHouse.h"
|
||||||
#include "OpDefs/GopTransform.hpp"
|
#include "OpDefs/GopTransform.hpp"
|
||||||
@@ -9,16 +10,26 @@ extern "C"
|
|||||||
BOOST_SYMBOL_EXPORT void newSopOperator(enzo::op::addOperatorPtr addOperator)
|
BOOST_SYMBOL_EXPORT void newSopOperator(enzo::op::addOperatorPtr addOperator)
|
||||||
{
|
{
|
||||||
addOperator(
|
addOperator(
|
||||||
"transform",
|
enzo::op::OpInfo {
|
||||||
"Transform",
|
"transform",
|
||||||
&GopTransform::ctor,
|
"Transform",
|
||||||
GopTransform::parameterList
|
&GopTransform::ctor,
|
||||||
|
GopTransform::parameterList,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
}
|
||||||
);
|
);
|
||||||
addOperator(
|
addOperator(
|
||||||
"house",
|
enzo::op::OpInfo {
|
||||||
"House",
|
"house",
|
||||||
&GOP_house::ctor,
|
"House",
|
||||||
GOP_house::parameterList
|
&GOP_house::ctor,
|
||||||
|
GOP_house::parameterList,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user