feat: add string parameter
This commit is contained in:
@@ -49,3 +49,19 @@ enzo::bt::floatT enzo::op::Context::evalFloatParm(const char* parmName, const un
|
||||
throw std::runtime_error("Parameter weak ptr invalid");
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: cache value
|
||||
enzo::bt::String enzo::op::Context::evalStringParm(const char* parmName, const unsigned int index) const
|
||||
{
|
||||
enzo::nt::GeometryOperator& selfOp = networkManager_.getGeoOperator(opId_);
|
||||
std::weak_ptr<prm::Parameter> parameter = selfOp.getParameter(parmName);
|
||||
|
||||
if(auto sharedParm = parameter.lock())
|
||||
{
|
||||
return sharedParm->evalString(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("Parameter weak ptr invalid");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ public:
|
||||
Context(enzo::nt::OpId opId, enzo::nt::NetworkManager& networkManager);
|
||||
enzo::geo::Geometry cloneInputGeo(unsigned int inputIndex);
|
||||
bt::floatT evalFloatParm(const char* parmName, const unsigned int index=0) const;
|
||||
bt::String evalStringParm(const char* parmName, const unsigned int index=0) const;
|
||||
private:
|
||||
enzo::nt::OpId opId_;
|
||||
enzo::nt::NetworkManager& networkManager_;
|
||||
|
||||
@@ -24,6 +24,13 @@ void enzo::nt::GeometryOpDef::setOutputGeometry(unsigned int outputIndex, enzo::
|
||||
outputGeometry_[outputIndex] = geometry;
|
||||
}
|
||||
|
||||
void enzo::nt::GeometryOpDef::throwError(std::string error)
|
||||
{
|
||||
std::cerr << "NODE EXCEPTION: " << error << "\n";
|
||||
|
||||
}
|
||||
|
||||
|
||||
unsigned int enzo::nt::GeometryOpDef::getMinInputs() const
|
||||
{
|
||||
return opInfo_.minInputs;
|
||||
|
||||
@@ -20,6 +20,8 @@ public:
|
||||
virtual void cookOp(op::Context context) = 0;
|
||||
geo::Geometry& getOutputGeo(unsigned outputIndex);
|
||||
|
||||
void throwError(std::string error);
|
||||
|
||||
unsigned int getMinInputs() const;
|
||||
unsigned int getMaxInputs() const;
|
||||
unsigned int getMaxOutputs() const;
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
#include "Engine/Parameter/FloatType.h"
|
||||
@@ -1,12 +0,0 @@
|
||||
#pragma once
|
||||
#include "Engine/Parameter/Type.h"
|
||||
|
||||
// namespace enzo::prm
|
||||
// {
|
||||
// class FloatType
|
||||
// : public Type
|
||||
// {
|
||||
// public:
|
||||
|
||||
// };
|
||||
// }
|
||||
@@ -8,6 +8,7 @@ enzo::prm::Parameter::Parameter(Template prmTemplate)
|
||||
: template_{prmTemplate}
|
||||
{
|
||||
floatValues_ = std::vector<bt::floatT>(prmTemplate.getSize(), prmTemplate.getDefault());
|
||||
stringValues_ = std::vector<bt::String>(prmTemplate.getSize(), "default");
|
||||
std::cout << "created new parameter: " << prmTemplate.getName() << "\n";
|
||||
}
|
||||
|
||||
@@ -23,21 +24,33 @@ enzo::bt::floatT enzo::prm::Parameter::evalFloat(unsigned int index) const
|
||||
return floatValues_[index];
|
||||
}
|
||||
|
||||
enzo::bt::String enzo::prm::Parameter::evalString(unsigned int index) const
|
||||
{
|
||||
if(index >= stringValues_.size())
|
||||
throw std::out_of_range("Cannot access index: " + std::to_string(index) + " for parameter: " + getName());
|
||||
return stringValues_[index];
|
||||
}
|
||||
|
||||
|
||||
|
||||
enzo::prm::Type enzo::prm::Parameter::getType() const
|
||||
{
|
||||
return template_.getType();
|
||||
}
|
||||
|
||||
enzo::bt::String enzo::prm::Parameter::evalString() const
|
||||
{
|
||||
return stringValue_;
|
||||
}
|
||||
|
||||
void enzo::prm::Parameter::setFloat(bt::floatT value, unsigned int index)
|
||||
{
|
||||
std::cout << "accessing at: " << index << "\n";
|
||||
std::cout << "size: " << floatValues_.size() << "\n";
|
||||
if(index >= floatValues_.size())
|
||||
throw std::out_of_range("Cannot access index: " + std::to_string(index) + " for parameter: " + getName());
|
||||
floatValues_[index] = value;
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
void enzo::prm::Parameter::setString(bt::String value, unsigned int index)
|
||||
{
|
||||
if(index >= stringValues_.size())
|
||||
throw std::out_of_range("Cannot access index: " + std::to_string(index) + " for parameter: " + getName());
|
||||
stringValues_[index] = value;
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
@@ -10,16 +10,19 @@ class Parameter
|
||||
public:
|
||||
Parameter(Template prmTemplate);
|
||||
std::string getName() const;
|
||||
bt::floatT evalFloat(unsigned int index=0) const;
|
||||
bt::String evalString() const;
|
||||
enzo::prm::Type getType() const;
|
||||
|
||||
bt::floatT evalFloat(unsigned int index=0) const;
|
||||
bt::String evalString(unsigned int index=0) const;
|
||||
|
||||
void setFloat(bt::floatT value, unsigned int index=0);
|
||||
void setString(bt::String value, unsigned int index=0);
|
||||
|
||||
boost::signals2::signal<void ()> valueChanged;
|
||||
private:
|
||||
Template template_;
|
||||
std::vector<bt::floatT> floatValues_;
|
||||
bt::String stringValue_ = "";
|
||||
std::vector<bt::String> stringValues_;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#include "Gui/Parameters/AbstractFormParm.h"
|
||||
#include "Engine/Types.h"
|
||||
#include "Gui/Parameters/AbstractSliderParm.h"
|
||||
#include "Gui/Parameters/StringParm.h"
|
||||
#include <qboxlayout.h>
|
||||
#include <QLabel>
|
||||
#include <iostream>
|
||||
#include <qlabel.h>
|
||||
#include <string>
|
||||
|
||||
|
||||
enzo::ui::AbstractFormParm::AbstractFormParm(std::weak_ptr<prm::Parameter> parameter)
|
||||
@@ -47,9 +49,21 @@ enzo::ui::AbstractFormParm::AbstractFormParm(std::weak_ptr<prm::Parameter> param
|
||||
connect(slider2, &AbstractSliderParm::valueChanged, this, [this](bt::floatT value){this->changeValue(value, 1);});
|
||||
connect(slider3, &AbstractSliderParm::valueChanged, this, [this](bt::floatT value){this->changeValue(value, 2);});
|
||||
break;
|
||||
}
|
||||
case prm::Type::STRING:
|
||||
{
|
||||
StringParm* stringParm = new StringParm();
|
||||
|
||||
connect(stringParm, &StringParm::valueChanged, this, [this](bt::String value){this->changeValue(value, 0);});
|
||||
|
||||
mainLayout_->addWidget(stringParm);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
default:
|
||||
throw std::runtime_error("Parameter panel: paremeter type not accounted for");
|
||||
throw std::runtime_error("Parameter panel: paremeter type not accounted for " + std::to_string(static_cast<int>(sharedParameter->getType())));
|
||||
|
||||
}
|
||||
|
||||
@@ -92,3 +106,18 @@ void enzo::ui::AbstractFormParm::changeValue(enzo::bt::floatT value, unsigned in
|
||||
|
||||
}
|
||||
|
||||
void enzo::ui::AbstractFormParm::changeValue(enzo::bt::String value, unsigned int index)
|
||||
{
|
||||
if(auto sharedParameter=parameter_.lock())
|
||||
{
|
||||
sharedParameter->setString(value, index);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "ERROR: parameter no longer exists\n";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ public:
|
||||
|
||||
protected Q_SLOTS:
|
||||
void changeValue(bt::floatT value, unsigned int index=0);
|
||||
void changeValue(bt::String value, unsigned int index=0);
|
||||
|
||||
private:
|
||||
QHBoxLayout* mainLayout_;
|
||||
|
||||
52
src/Gui/Parameters/StringParm.cpp
Normal file
52
src/Gui/Parameters/StringParm.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "Gui/Parameters/StringParm.h"
|
||||
#include "Engine/Types.h"
|
||||
#include <QPainter>
|
||||
#include <QPaintEvent>
|
||||
#include <QLabel>
|
||||
#include <iostream>
|
||||
#include <qboxlayout.h>
|
||||
#include <qnamespace.h>
|
||||
#include <algorithm>
|
||||
#include <QLineEdit>
|
||||
#include <string>
|
||||
|
||||
|
||||
enzo::ui::StringParm::StringParm(QWidget *parent)
|
||||
: QLineEdit(parent)
|
||||
{
|
||||
// tells qt to style the widget even though it's a Q_OBJECT
|
||||
setAttribute(Qt::WA_StyledBackground, true);
|
||||
setFixedHeight(24);
|
||||
|
||||
|
||||
// setAlignment(Qt::AlignCenter);
|
||||
// setStyleSheet("background-color: none;");
|
||||
setProperty("type", "StringParm");
|
||||
setStyleSheet(R"(
|
||||
QWidget[type="StringParm"]
|
||||
{
|
||||
border-radius: 6px;
|
||||
border: 1px solid #383838;
|
||||
padding: 0px 5px 0px 5px;
|
||||
}
|
||||
)");
|
||||
|
||||
setText(QString::fromStdString(value_));
|
||||
|
||||
connect(this, &QLineEdit::textEdited, this, &enzo::ui::StringParm::setValueQString);
|
||||
}
|
||||
|
||||
void enzo::ui::StringParm::setValue(bt::String value)
|
||||
{
|
||||
value_ = value;
|
||||
setText(QString::fromStdString(value_));
|
||||
|
||||
valueChanged(value_);
|
||||
|
||||
}
|
||||
|
||||
void enzo::ui::StringParm::setValueQString(QString value)
|
||||
{
|
||||
value_ = value.toStdString();
|
||||
valueChanged(value_);
|
||||
}
|
||||
32
src/Gui/Parameters/StringParm.h
Normal file
32
src/Gui/Parameters/StringParm.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include "Engine/Types.h"
|
||||
#include <QWidget>
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
|
||||
namespace enzo::ui
|
||||
{
|
||||
|
||||
class StringParm
|
||||
: public QLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
StringParm(QWidget *parent = nullptr);
|
||||
void setValue(bt::String value);
|
||||
void setValueQString(QString value);
|
||||
|
||||
Q_SIGNALS:
|
||||
void valueChanged(bt::String value);
|
||||
|
||||
private:
|
||||
bt::String value_;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <oneapi/tbb/parallel_for.h>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
GopGeometryImport::GopGeometryImport(enzo::nt::NetworkManager* network, enzo::op::OpInfo opInfo)
|
||||
: GeometryOpDef(network, opInfo)
|
||||
@@ -19,11 +19,27 @@ void GopGeometryImport::cookOp(enzo::op::Context context)
|
||||
|
||||
if(outputRequested(0))
|
||||
{
|
||||
std::string filePath = "/home/parker/Downloads/Rat_Placeholder_Polycount_12.obj";
|
||||
std::cout << "COOKING IMPORT NODE\n";
|
||||
|
||||
geo::Geometry geo;
|
||||
|
||||
bt::String filePath = context.evalStringParm("filePath");
|
||||
boost::trim(filePath);
|
||||
if(filePath.size()<4)
|
||||
{
|
||||
throwError("file path too small");
|
||||
setOutputGeometry(0, geo);
|
||||
return;
|
||||
}
|
||||
|
||||
std::string fileExt = filePath.substr(filePath.size()-4, filePath.size());
|
||||
|
||||
if(fileExt!=".obj")
|
||||
{
|
||||
throwError("File path not accepted: " + fileExt);
|
||||
setOutputGeometry(0, geo);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
auto PAttr = geo.getAttribByName(ga::AttrOwner::POINT, "P");
|
||||
ga::AttributeHandleVector3 PAttrHandle(PAttr);
|
||||
|
||||
@@ -37,6 +53,7 @@ void GopGeometryImport::cookOp(enzo::op::Context context)
|
||||
if(!file.is_open())
|
||||
{
|
||||
std::cerr << "Failed to open file " << filePath << "\n";
|
||||
setOutputGeometry(0, geo);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -105,6 +122,7 @@ void GopGeometryImport::cookOp(enzo::op::Context context)
|
||||
|
||||
enzo::prm::Template GopGeometryImport::parameterList[] =
|
||||
{
|
||||
enzo::prm::Template(enzo::prm::Type::STRING, "filePath", 1),
|
||||
enzo::prm::Template(enzo::prm::Type::FLOAT, "size", 1),
|
||||
enzo::prm::Terminator
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user