#include "Engine/Operator/GeometryOperator.h" #include #include "Engine/Network/NetworkManager.h" #include #include "Engine/Operator/Context.h" #include "Engine/Parameter/Parameter.h" #include "Engine/Parameter/Template.h" #include using namespace enzo; void enzo::nt::connectOperators(enzo::nt::OpId inputOpId, unsigned int inputIndex, enzo::nt::OpId outputOpId, unsigned int outputIndex) { auto& nm = nt::nm(); auto& inputOp = nm.getGeoOperator(inputOpId); auto& outputOp = nm.getGeoOperator(outputOpId); auto newConnection = std::make_shared(inputOpId, inputIndex, outputOpId, outputIndex); // set output on the upper operator inputOp.addOutputConnection(newConnection); // set input on the lower operator outputOp.addInputConnection(newConnection); } nt::GeometryOperator::GeometryOperator(enzo::nt::OpId opId, op::OpInfo opInfo) : opId_{opId}, opInfo_{opInfo}, opDef_(opInfo.ctorFunc(opId)) { // TODO: drive by geometry definition maxInputs_=4; maxOutputs_=4; initParameters(); } void nt::GeometryOperator::initParameters() { for(const prm::Template* t = opInfo_.templates; t->isValid(); ++t) { std::cout << "name: " << t->getName() << "\n"; // create parameter auto parameter = std::make_shared(*t); parameter->valueChanged.connect(boost::bind(&GeometryOperator::dirtyNode, this)); parameters_.push_back(parameter); } } void enzo::nt::GeometryOperator::dirtyNode() { dirty_=true; nodeDirtied(opId_); } void enzo::nt::GeometryOperator::cookOp(op::Context context) { opDef_->cookOp(context); dirty_=false; } geo::Geometry& enzo::nt::GeometryOperator::getOutputGeo(unsigned outputIndex) { return opDef_->getOutputGeo(outputIndex); } void nt::GeometryOperator::addInputConnection(std::shared_ptr connection) { std::cout << "Input connection added\nConnecting ops " << connection->getInputOpId() << " -> " << connection->getOutputOpId() << "\n"; std::cout << "Connecting index " << connection->getInputIndex() << " -> " << connection->getOutputIndex() << "\n"; inputConnections_.push_back(connection); std::cout << "size: " << inputConnections_.size() << "\n"; } void nt::GeometryOperator::addOutputConnection(std::shared_ptr connection) { std::cout << "Output connection added\nConnecting ops " << connection->getInputOpId() << " -> " << connection->getOutputOpId() << "\n"; std::cout << "Connecting index " << connection->getInputIndex() << " -> " << connection->getOutputIndex() << "\n"; outputConnections_.push_back(connection); std::cout << "size: " << outputConnections_.size() << "\n"; } std::weak_ptr nt::GeometryOperator::getParameter(std::string parameterName) { for(auto parm : parameters_) { if(parm->getName()==parameterName) { return parm; } } return std::weak_ptr(); } std::vector> nt::GeometryOperator::getInputConnections() const { std::vector> inputConnections; for(std::shared_ptr connection : inputConnections_) { inputConnections.push_back(connection); } return inputConnections; } std::vector> nt::GeometryOperator::getParameters() { return {parameters_.begin(), parameters_.end()}; } std::vector> nt::GeometryOperator::getOutputConnections() const { std::vector> outputConnections; for(std::shared_ptr connection : outputConnections_) { outputConnections.push_back(connection); } return outputConnections; } // std::optional nt::GeometryOperator::getInput(unsigned int inputNumber) const // { // if(inputNumber>=maxInputs_) // { // return std::nullopt; // } // return inputIds_.at(inputNumber); // } // std::optional nt::GeometryOperator::getOutput(unsigned int outputNumber) const // { // if(outputNumber>=maxOutputs_) // { // return std::nullopt; // } // return outputIds_.at(outputNumber); // } unsigned int nt::GeometryOperator::getMaxInputs() const { return maxInputs_; } unsigned int nt::GeometryOperator::getMaxOutputs() const { return maxOutputs_; }