feat: add string parameter
This commit is contained in:
@@ -49,6 +49,7 @@ set(GUI_SOURCES
|
|||||||
src/Gui/Parameters/AbstractSliderParm.cpp
|
src/Gui/Parameters/AbstractSliderParm.cpp
|
||||||
src/Gui/Parameters/AbstractFormParm.cpp
|
src/Gui/Parameters/AbstractFormParm.cpp
|
||||||
src/Gui/Parameters/FloatParm.cpp
|
src/Gui/Parameters/FloatParm.cpp
|
||||||
|
src/Gui/Parameters/StringParm.cpp
|
||||||
)
|
)
|
||||||
set(ENGINE_INCLUDE_DIRECTORIES
|
set(ENGINE_INCLUDE_DIRECTORIES
|
||||||
src
|
src
|
||||||
|
|||||||
@@ -49,3 +49,19 @@ enzo::bt::floatT enzo::op::Context::evalFloatParm(const char* parmName, const un
|
|||||||
throw std::runtime_error("Parameter weak ptr invalid");
|
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);
|
Context(enzo::nt::OpId opId, enzo::nt::NetworkManager& networkManager);
|
||||||
enzo::geo::Geometry cloneInputGeo(unsigned int inputIndex);
|
enzo::geo::Geometry cloneInputGeo(unsigned int inputIndex);
|
||||||
bt::floatT evalFloatParm(const char* parmName, const unsigned int index=0) const;
|
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:
|
private:
|
||||||
enzo::nt::OpId opId_;
|
enzo::nt::OpId opId_;
|
||||||
enzo::nt::NetworkManager& networkManager_;
|
enzo::nt::NetworkManager& networkManager_;
|
||||||
|
|||||||
@@ -24,6 +24,13 @@ void enzo::nt::GeometryOpDef::setOutputGeometry(unsigned int outputIndex, enzo::
|
|||||||
outputGeometry_[outputIndex] = geometry;
|
outputGeometry_[outputIndex] = geometry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void enzo::nt::GeometryOpDef::throwError(std::string error)
|
||||||
|
{
|
||||||
|
std::cerr << "NODE EXCEPTION: " << error << "\n";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned int enzo::nt::GeometryOpDef::getMinInputs() const
|
unsigned int enzo::nt::GeometryOpDef::getMinInputs() const
|
||||||
{
|
{
|
||||||
return opInfo_.minInputs;
|
return opInfo_.minInputs;
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ public:
|
|||||||
virtual void cookOp(op::Context context) = 0;
|
virtual void cookOp(op::Context context) = 0;
|
||||||
geo::Geometry& getOutputGeo(unsigned outputIndex);
|
geo::Geometry& getOutputGeo(unsigned outputIndex);
|
||||||
|
|
||||||
|
void throwError(std::string error);
|
||||||
|
|
||||||
unsigned int getMinInputs() const;
|
unsigned int getMinInputs() const;
|
||||||
unsigned int getMaxInputs() const;
|
unsigned int getMaxInputs() const;
|
||||||
unsigned int getMaxOutputs() 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}
|
: template_{prmTemplate}
|
||||||
{
|
{
|
||||||
floatValues_ = std::vector<bt::floatT>(prmTemplate.getSize(), prmTemplate.getDefault());
|
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";
|
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];
|
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
|
enzo::prm::Type enzo::prm::Parameter::getType() const
|
||||||
{
|
{
|
||||||
return template_.getType();
|
return template_.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
enzo::bt::String enzo::prm::Parameter::evalString() const
|
|
||||||
{
|
|
||||||
return stringValue_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void enzo::prm::Parameter::setFloat(bt::floatT value, unsigned int index)
|
void enzo::prm::Parameter::setFloat(bt::floatT value, unsigned int index)
|
||||||
{
|
{
|
||||||
std::cout << "accessing at: " << index << "\n";
|
if(index >= floatValues_.size())
|
||||||
std::cout << "size: " << floatValues_.size() << "\n";
|
throw std::out_of_range("Cannot access index: " + std::to_string(index) + " for parameter: " + getName());
|
||||||
floatValues_[index] = value;
|
floatValues_[index] = value;
|
||||||
valueChanged();
|
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:
|
public:
|
||||||
Parameter(Template prmTemplate);
|
Parameter(Template prmTemplate);
|
||||||
std::string getName() const;
|
std::string getName() const;
|
||||||
bt::floatT evalFloat(unsigned int index=0) const;
|
|
||||||
bt::String evalString() const;
|
|
||||||
enzo::prm::Type getType() 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 setFloat(bt::floatT value, unsigned int index=0);
|
||||||
|
void setString(bt::String value, unsigned int index=0);
|
||||||
|
|
||||||
boost::signals2::signal<void ()> valueChanged;
|
boost::signals2::signal<void ()> valueChanged;
|
||||||
private:
|
private:
|
||||||
Template template_;
|
Template template_;
|
||||||
std::vector<bt::floatT> floatValues_;
|
std::vector<bt::floatT> floatValues_;
|
||||||
bt::String stringValue_ = "";
|
std::vector<bt::String> stringValues_;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
#include "Gui/Parameters/AbstractFormParm.h"
|
#include "Gui/Parameters/AbstractFormParm.h"
|
||||||
#include "Engine/Types.h"
|
#include "Engine/Types.h"
|
||||||
#include "Gui/Parameters/AbstractSliderParm.h"
|
#include "Gui/Parameters/AbstractSliderParm.h"
|
||||||
|
#include "Gui/Parameters/StringParm.h"
|
||||||
#include <qboxlayout.h>
|
#include <qboxlayout.h>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <qlabel.h>
|
#include <qlabel.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
enzo::ui::AbstractFormParm::AbstractFormParm(std::weak_ptr<prm::Parameter> parameter)
|
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(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);});
|
connect(slider3, &AbstractSliderParm::valueChanged, this, [this](bt::floatT value){this->changeValue(value, 2);});
|
||||||
break;
|
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:
|
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:
|
protected Q_SLOTS:
|
||||||
void changeValue(bt::floatT value, unsigned int index=0);
|
void changeValue(bt::floatT value, unsigned int index=0);
|
||||||
|
void changeValue(bt::String value, unsigned int index=0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHBoxLayout* mainLayout_;
|
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 <oneapi/tbb/parallel_for.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <boost/algorithm/string/split.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
GopGeometryImport::GopGeometryImport(enzo::nt::NetworkManager* network, enzo::op::OpInfo opInfo)
|
GopGeometryImport::GopGeometryImport(enzo::nt::NetworkManager* network, enzo::op::OpInfo opInfo)
|
||||||
: GeometryOpDef(network, opInfo)
|
: GeometryOpDef(network, opInfo)
|
||||||
@@ -19,11 +19,27 @@ void GopGeometryImport::cookOp(enzo::op::Context context)
|
|||||||
|
|
||||||
if(outputRequested(0))
|
if(outputRequested(0))
|
||||||
{
|
{
|
||||||
std::string filePath = "/home/parker/Downloads/Rat_Placeholder_Polycount_12.obj";
|
|
||||||
std::cout << "COOKING IMPORT NODE\n";
|
|
||||||
|
|
||||||
geo::Geometry geo;
|
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");
|
auto PAttr = geo.getAttribByName(ga::AttrOwner::POINT, "P");
|
||||||
ga::AttributeHandleVector3 PAttrHandle(PAttr);
|
ga::AttributeHandleVector3 PAttrHandle(PAttr);
|
||||||
|
|
||||||
@@ -37,6 +53,7 @@ void GopGeometryImport::cookOp(enzo::op::Context context)
|
|||||||
if(!file.is_open())
|
if(!file.is_open())
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to open file " << filePath << "\n";
|
std::cerr << "Failed to open file " << filePath << "\n";
|
||||||
|
setOutputGeometry(0, geo);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,6 +122,7 @@ void GopGeometryImport::cookOp(enzo::op::Context context)
|
|||||||
|
|
||||||
enzo::prm::Template GopGeometryImport::parameterList[] =
|
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::Template(enzo::prm::Type::FLOAT, "size", 1),
|
||||||
enzo::prm::Terminator
|
enzo::prm::Terminator
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user