feat: pass node info with template
This commit is contained in:
@@ -76,37 +76,37 @@ target_link_libraries(${AppExec} PRIVATE Qt6::Core Qt6::Widgets Qt6::SvgWidgets
|
|||||||
target_include_directories(${AppExec} PUBLIC src)
|
target_include_directories(${AppExec} PUBLIC src)
|
||||||
|
|
||||||
# tests
|
# tests
|
||||||
Include(FetchContent)
|
# Include(FetchContent)
|
||||||
|
|
||||||
FetchContent_Declare(
|
# FetchContent_Declare(
|
||||||
Catch2
|
# Catch2
|
||||||
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
# GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
||||||
GIT_TAG v3.8.1 # or a later release
|
# GIT_TAG v3.8.1 # or a later release
|
||||||
)
|
# )
|
||||||
|
|
||||||
FetchContent_MakeAvailable(Catch2)
|
# FetchContent_MakeAvailable(Catch2)
|
||||||
|
|
||||||
add_executable(${TestExec}
|
# add_executable(${TestExec}
|
||||||
${ENGINE_SOURCES}
|
# ${ENGINE_SOURCES}
|
||||||
tests/main-tests.cpp
|
# tests/main-tests.cpp
|
||||||
tests/OperatorTests.cpp
|
# tests/OperatorTests.cpp
|
||||||
tests/NetworkTests.cpp
|
# tests/NetworkTests.cpp
|
||||||
)
|
# )
|
||||||
target_link_libraries(${TestExec} PRIVATE Catch2::Catch2WithMain Eigen3::Eigen Qt6::Core TBB::tbb Boost::filesystem Boost::system)
|
# target_link_libraries(${TestExec} PRIVATE Catch2::Catch2WithMain Eigen3::Eigen Qt6::Core TBB::tbb Boost::filesystem Boost::system)
|
||||||
target_compile_definitions(${TestExec} PRIVATE UNIT_TEST)
|
# target_compile_definitions(${TestExec} PRIVATE UNIT_TEST)
|
||||||
target_include_directories(${TestExec} PUBLIC
|
# target_include_directories(${TestExec} PUBLIC
|
||||||
src
|
# src
|
||||||
${BOOST_INCLUDE_DIRS}
|
# ${BOOST_INCLUDE_DIRS}
|
||||||
)
|
# )
|
||||||
|
|
||||||
# benchmarks
|
# # benchmarks
|
||||||
add_executable(${BenchExec}
|
# add_executable(${BenchExec}
|
||||||
${ENGINE_SOURCES}
|
# ${ENGINE_SOURCES}
|
||||||
|
|
||||||
tests/Benchmarks.cpp
|
# tests/Benchmarks.cpp
|
||||||
)
|
# )
|
||||||
target_link_libraries(${BenchExec} PRIVATE Catch2::Catch2WithMain Eigen3::Eigen Qt6::Core TBB::tbb Boost::filesystem Boost::system)
|
# target_link_libraries(${BenchExec} PRIVATE Catch2::Catch2WithMain Eigen3::Eigen Qt6::Core TBB::tbb Boost::filesystem Boost::system)
|
||||||
target_compile_definitions(${BenchExec} PRIVATE UNIT_TEST)
|
# target_compile_definitions(${BenchExec} PRIVATE UNIT_TEST)
|
||||||
target_include_directories(${BenchExec} PUBLIC src)
|
# target_include_directories(${BenchExec} PUBLIC src)
|
||||||
|
|
||||||
add_subdirectory(src/OpDefs)
|
# add_subdirectory(src/OpDefs)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "Engine/Operator/GeometryOperator.h"
|
#include "Engine/Operator/GeometryOperator.h"
|
||||||
#include "Engine/Operator/Attribute.h"
|
#include "Engine/Operator/Attribute.h"
|
||||||
#include "Engine/Operator/AttributeHandle.h"
|
#include "Engine/Operator/AttributeHandle.h"
|
||||||
|
#include "Engine/Operator/OpInfo.h"
|
||||||
#include "Engine/Types.h"
|
#include "Engine/Types.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@@ -10,11 +11,11 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
enzo::nt::OpId enzo::nt::NetworkManager::addOperator(nt::opConstructor ctorFunc)
|
enzo::nt::OpId enzo::nt::NetworkManager::addOperator(op::OpInfo opInfo)
|
||||||
{
|
{
|
||||||
|
|
||||||
maxOpId_++;
|
maxOpId_++;
|
||||||
gopStore_.emplace(maxOpId_, std::make_unique<GeometryOperator>(maxOpId_, ctorFunc));
|
gopStore_.emplace(maxOpId_, std::make_unique<GeometryOperator>(maxOpId_, opInfo));
|
||||||
std::cout << "adding operator " << maxOpId_ << "\n";
|
std::cout << "adding operator " << maxOpId_ << "\n";
|
||||||
|
|
||||||
return maxOpId_;
|
return maxOpId_;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public:
|
|||||||
static NetworkManager& getInstance();
|
static NetworkManager& getInstance();
|
||||||
|
|
||||||
// functions
|
// functions
|
||||||
OpId addOperator(nt::opConstructor ctorFunc);
|
OpId addOperator(op::OpInfo opInfo);
|
||||||
std::optional<OpId> getDisplayOp();
|
std::optional<OpId> getDisplayOp();
|
||||||
bool isValidOp(nt::OpId opId);
|
bool isValidOp(nt::OpId opId);
|
||||||
GeometryOperator& getGeoOperator(nt::OpId opId);
|
GeometryOperator& getGeoOperator(nt::OpId opId);
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ void enzo::nt::connectOperators(enzo::nt::OpId inputOpId, unsigned int inputInde
|
|||||||
outputOp.addInputConnection(newConnection);
|
outputOp.addInputConnection(newConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
nt::GeometryOperator::GeometryOperator(enzo::nt::OpId opId, nt::opConstructor ctorFunc)
|
nt::GeometryOperator::GeometryOperator(enzo::nt::OpId opId, op::OpInfo opinfo)
|
||||||
: opId_{opId}, opDef_(ctorFunc(opId))
|
: opId_{opId}, opDef_(opinfo.ctorFunc(opId))
|
||||||
{
|
{
|
||||||
// TODO: drive by geometry definition
|
// TODO: drive by geometry definition
|
||||||
maxInputs_=4;
|
maxInputs_=4;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Engine/Operator/GeometryConnection.h"
|
#include "Engine/Operator/GeometryConnection.h"
|
||||||
|
#include "Engine/Operator/OpInfo.h"
|
||||||
#include "Engine/Operator/GeometryOpDef.h"
|
#include "Engine/Operator/GeometryOpDef.h"
|
||||||
#include "Engine/Types.h"
|
#include "Engine/Types.h"
|
||||||
#include <optional>
|
#include <optional>
|
||||||
@@ -11,7 +12,7 @@ void connectOperators(enzo::nt::OpId inputOpId, unsigned int inputIndex, enzo::n
|
|||||||
class GeometryOperator
|
class GeometryOperator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GeometryOperator(enzo::nt::OpId opId, nt::opConstructor ctorFunc);
|
GeometryOperator(enzo::nt::OpId opId, op::OpInfo opinfo);
|
||||||
|
|
||||||
// disable copying
|
// disable copying
|
||||||
GeometryOperator(const GeometryOperator&) = delete;
|
GeometryOperator(const GeometryOperator&) = delete;
|
||||||
|
|||||||
15
src/Engine/Operator/OpInfo.h
Normal file
15
src/Engine/Operator/OpInfo.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include "Engine/Operator/GeometryOpDef.h"
|
||||||
|
#include "Engine/Parameter/Template.h"
|
||||||
|
|
||||||
|
namespace enzo::op
|
||||||
|
{
|
||||||
|
struct OpInfo
|
||||||
|
{
|
||||||
|
std::string internalName;
|
||||||
|
std::string displayName;
|
||||||
|
enzo::nt::opConstructor ctorFunc;
|
||||||
|
enzo::prm::Template* templates;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -3,11 +3,18 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
void enzo::op::OperatorTable::addOperator(const char* internalName, const char* displayName, nt::opConstructor ctorFunc, prm::Template templateList[])
|
void enzo::op::OperatorTable::addOperator(const char* internalName, const char* displayName, nt::opConstructor ctorFunc, prm::Template* templates)
|
||||||
{
|
{
|
||||||
std::cout << "OPERATOR TABLE ADDED\n";
|
std::cout << "OPERATOR TABLE ADDED\n";
|
||||||
std::cout << "adding operator: " << displayName << "\n";
|
std::cout << "adding operator: " << displayName << "\n";
|
||||||
opInfoStore_.push_back({internalName, displayName, ctorFunc});
|
enzo::op::OpInfo info {
|
||||||
|
internalName,
|
||||||
|
displayName,
|
||||||
|
ctorFunc,
|
||||||
|
templates
|
||||||
|
};
|
||||||
|
|
||||||
|
opInfoStore_.push_back(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
enzo::nt::opConstructor enzo::op::OperatorTable::getOpConstructor(std::string name)
|
enzo::nt::opConstructor enzo::op::OperatorTable::getOpConstructor(std::string name)
|
||||||
@@ -22,6 +29,18 @@ enzo::nt::opConstructor enzo::op::OperatorTable::getOpConstructor(std::string na
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::optional<enzo::op::OpInfo> enzo::op::OperatorTable::getOpInfo(std::string name)
|
||||||
|
{
|
||||||
|
for(auto it = opInfoStore_.begin(); it!=opInfoStore_.end(); ++it)
|
||||||
|
{
|
||||||
|
if(it->internalName==name)
|
||||||
|
{
|
||||||
|
return *it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<enzo::op::OpInfo> enzo::op::OperatorTable::getData()
|
std::vector<enzo::op::OpInfo> enzo::op::OperatorTable::getData()
|
||||||
{
|
{
|
||||||
return opInfoStore_;
|
return opInfoStore_;
|
||||||
|
|||||||
@@ -3,29 +3,25 @@
|
|||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#include "Engine/Network/NetworkManager.h"
|
#include "Engine/Network/NetworkManager.h"
|
||||||
#include "Engine/Operator/GeometryOpDef.h"
|
#include "Engine/Operator/GeometryOpDef.h"
|
||||||
|
#include "Engine/Operator/OpInfo.h"
|
||||||
#include "Engine/Parameter/Template.h"
|
#include "Engine/Parameter/Template.h"
|
||||||
|
|
||||||
|
|
||||||
namespace enzo::op
|
namespace enzo::op
|
||||||
{
|
{
|
||||||
struct OpInfo
|
|
||||||
{
|
|
||||||
std::string internalName;
|
|
||||||
std::string displayName;
|
|
||||||
enzo::nt::opConstructor ctorFunc;
|
|
||||||
};
|
|
||||||
|
|
||||||
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 templateList[]);
|
static void addOperator(const char* internalName, const char* displayName, nt::opConstructor ctorFunc, prm::Template* templates);
|
||||||
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 std::vector<OpInfo> getData();
|
static std::vector<OpInfo> getData();
|
||||||
// TODO: move to better spot (maybe engine class)
|
// TODO: move to better spot (maybe engine class)
|
||||||
static void initPlugins();
|
static void initPlugins();
|
||||||
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 (*)(const char* internalName, const char* displayName, nt::opConstructor ctorFunc, prm::Template* templateList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
7
src/Engine/Parameter/FloatParm.cpp
Normal file
7
src/Engine/Parameter/FloatParm.cpp
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include "Engine/Parameter/FloatParm.h"
|
||||||
|
|
||||||
|
|
||||||
|
enzo::prm::FloatParm::FloatParm(Template prmTemplate)
|
||||||
|
: template_{prmTemplate}
|
||||||
|
{
|
||||||
|
}
|
||||||
18
src/Engine/Parameter/FloatParm.h
Normal file
18
src/Engine/Parameter/FloatParm.h
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Engine/Parameter/Template.h"
|
||||||
|
#include "Engine/Types.h"
|
||||||
|
|
||||||
|
namespace enzo::prm
|
||||||
|
{
|
||||||
|
class FloatParm
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FloatParm(Template prmTemplate);
|
||||||
|
inline bt::floatT getValue() const {return value_;}
|
||||||
|
inline void setValue(bt::floatT value) {value_ = value;}
|
||||||
|
private:
|
||||||
|
Template template_;
|
||||||
|
bt::floatT value_ = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#include "Engine/Parameter/Template.h"
|
#include "Engine/Parameter/Template.h"
|
||||||
#include "Engine/Parameter/Type.h"
|
#include "Engine/Parameter/Type.h"
|
||||||
|
|
||||||
enzo::prm::Template::Template(enzo::prm::Type type)
|
enzo::prm::Template::Template(enzo::prm::Type type, const char* name)
|
||||||
: type_{type}
|
: type_{type}, name_{name}
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,11 @@ namespace enzo::prm
|
|||||||
class Template
|
class Template
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Template(enzo::prm::Type type);
|
Template(enzo::prm::Type type, const char* name);
|
||||||
private:
|
private:
|
||||||
enzo::prm::Type type_;
|
enzo::prm::Type type_;
|
||||||
|
// TODO: make a class that holds token and name
|
||||||
|
const char* name_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#include <qgraphicsitem.h>
|
#include <qgraphicsitem.h>
|
||||||
#include <qnamespace.h>
|
#include <qnamespace.h>
|
||||||
#include <QLine>
|
#include <QLine>
|
||||||
|
#include <stdexcept>
|
||||||
#include "Gui/Network/TabMenu.h"
|
#include "Gui/Network/TabMenu.h"
|
||||||
|
|
||||||
using namespace enzo;
|
using namespace enzo;
|
||||||
@@ -310,30 +311,35 @@ void Network::keyPressEvent(QKeyEvent *event)
|
|||||||
tabMenu_->showOnMouse();
|
tabMenu_->showOnMouse();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(Qt::Key_G):
|
// case(Qt::Key_G):
|
||||||
{
|
// {
|
||||||
if(auto newNode = createNode(op::OperatorTable::getOpConstructor("transform")))
|
// auto opInfo = op::OperatorTable::getOpInfo("transform");
|
||||||
{
|
// if(!opInfo.has_value()) {throw std::runtime_error("Couldn't find op info for: " + )}
|
||||||
newNode->setPos(viewPos);
|
// if(
|
||||||
}
|
// opInfo.has_value() &&
|
||||||
|
// auto newNode = createNode(opInfo)
|
||||||
|
// )
|
||||||
|
// {
|
||||||
|
// newNode->setPos(viewPos);
|
||||||
|
// }
|
||||||
|
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
case(Qt::Key_F):
|
// case(Qt::Key_F):
|
||||||
{
|
// {
|
||||||
if(auto newNode = createNode(op::OperatorTable::getOpConstructor("house")))
|
// if(auto newNode = createNode(op::OperatorTable::getOpInfo("house")))
|
||||||
{
|
// {
|
||||||
newNode->setPos(viewPos);
|
// newNode->setPos(viewPos);
|
||||||
}
|
// }
|
||||||
|
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeGraphic* Network::createNode(nt::opConstructor ctorFunc)
|
NodeGraphic* Network::createNode(op::OpInfo opInfo)
|
||||||
{
|
{
|
||||||
if(nt::OpId id = enzo::nt::nm().addOperator(ctorFunc))
|
if(nt::OpId id = enzo::nt::nm().addOperator(opInfo))
|
||||||
{
|
{
|
||||||
NodeGraphic* newNode = new NodeGraphic(id);
|
NodeGraphic* newNode = new NodeGraphic(id);
|
||||||
QPointF cursorPos = view_->mapToScene(mapFromGlobal(QCursor::pos()));
|
QPointF cursorPos = view_->mapToScene(mapFromGlobal(QCursor::pos()));
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public:
|
|||||||
DEFAULT,
|
DEFAULT,
|
||||||
MOVING_NODE
|
MOVING_NODE
|
||||||
};
|
};
|
||||||
NodeGraphic* createNode(enzo::nt::opConstructor ctorFunc);
|
NodeGraphic* createNode(enzo::op::OpInfo opInfo);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QLayout* mainLayout_;
|
QLayout* mainLayout_;
|
||||||
|
|||||||
@@ -171,11 +171,23 @@ void enzo::ui::TabMenu::textChanged(const QString &text)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void enzo::ui::TabMenu::createNode(std::string nodeName)
|
||||||
|
{
|
||||||
|
// get node info
|
||||||
|
std::optional<op::OpInfo> opInfo = op::OperatorTable::getOpInfo(nodeName);
|
||||||
|
// check valid result
|
||||||
|
if(!opInfo.has_value()) {throw std::runtime_error("Couldn't find op info for: " + nodeName);}
|
||||||
|
|
||||||
|
static_cast<Network*>(parentWidget())->createNode(opInfo.value());
|
||||||
|
}
|
||||||
|
|
||||||
void enzo::ui::TabMenu::nodeClicked()
|
void enzo::ui::TabMenu::nodeClicked()
|
||||||
{
|
{
|
||||||
|
// get name of button clicked
|
||||||
TabMenuButton* buttonClicked = static_cast<TabMenuButton*>(sender());
|
TabMenuButton* buttonClicked = static_cast<TabMenuButton*>(sender());
|
||||||
static_cast<Network*>(parentWidget())->createNode(op::OperatorTable::getOpConstructor(buttonClicked->nodeName));
|
|
||||||
|
createNode(buttonClicked->nodeName);
|
||||||
|
|
||||||
doHide();
|
doHide();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,7 +242,7 @@ bool enzo::ui::TabMenu::event(QEvent *event)
|
|||||||
if(visibleButtons_.size()==0) return true;
|
if(visibleButtons_.size()==0) return true;
|
||||||
if(selectionIndex_>=visibleButtons_.size()) selectionIndex_=visibleButtons_.size()-1;
|
if(selectionIndex_>=visibleButtons_.size()) selectionIndex_=visibleButtons_.size()-1;
|
||||||
auto button = visibleButtons_.at(selectionIndex_);
|
auto button = visibleButtons_.at(selectionIndex_);
|
||||||
static_cast<Network*>(parentWidget())->createNode(op::OperatorTable::getOpConstructor(button->nodeName));
|
createNode(button->nodeName);
|
||||||
doHide();
|
doHide();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ public:
|
|||||||
QString getDisplayText() {return displayText_;}
|
QString getDisplayText() {return displayText_;}
|
||||||
void setSelected(bool selected);
|
void setSelected(bool selected);
|
||||||
private:
|
private:
|
||||||
|
|
||||||
QHBoxLayout* mainLayout_;
|
QHBoxLayout* mainLayout_;
|
||||||
QLabel* textLabel_;
|
QLabel* textLabel_;
|
||||||
QSvgWidget* icon_;
|
QSvgWidget* icon_;
|
||||||
QString displayText_;
|
QString displayText_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class TabMenu
|
class TabMenu
|
||||||
@@ -42,6 +42,7 @@ private:
|
|||||||
DOWN
|
DOWN
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void createNode(std::string nodeName);
|
||||||
QVBoxLayout* mainLayout_;
|
QVBoxLayout* mainLayout_;
|
||||||
QLineEdit* searchBar_;
|
QLineEdit* searchBar_;
|
||||||
QScrollArea* nodeScrollArea_;
|
QScrollArea* nodeScrollArea_;
|
||||||
|
|||||||
@@ -38,5 +38,8 @@ void GopTransform::cookOp(enzo::op::Context context)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enzo::prm::Template GopTransform::parameterList[] = {};
|
enzo::prm::Template GopTransform::parameterList[] = {
|
||||||
|
enzo::prm::Template(enzo::prm::Type::FLOAT, "Test"),
|
||||||
|
enzo::prm::Template(enzo::prm::Type::FLOAT, "Test2")
|
||||||
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user