feat(geometrySpreadsheet): connect attribute buttons

This commit is contained in:
parker
2025-08-10 19:13:08 +01:00
parent 750dfea9a0
commit b245e5333e
9 changed files with 116 additions and 26 deletions

View File

@@ -124,6 +124,12 @@ std::vector<std::weak_ptr<prm::Parameter>> nt::GeometryOperator::getParameters()
return {parameters_.begin(), parameters_.end()}; return {parameters_.begin(), parameters_.end()};
} }
std::string nt::GeometryOperator::getLabel()
{
return getTypeName();
}
std::vector<std::weak_ptr<const nt::GeometryConnection>> nt::GeometryOperator::getOutputConnections() const std::vector<std::weak_ptr<const nt::GeometryConnection>> nt::GeometryOperator::getOutputConnections() const
{ {
return {outputConnections_.begin(), outputConnections_.end()}; return {outputConnections_.begin(), outputConnections_.end()};

View File

@@ -30,6 +30,7 @@ public:
std::vector<std::weak_ptr<prm::Parameter>> getParameters(); std::vector<std::weak_ptr<prm::Parameter>> getParameters();
std::weak_ptr<prm::Parameter> getParameter(std::string parameterName); std::weak_ptr<prm::Parameter> getParameter(std::string parameterName);
std::string getLabel(); // TODO: implement node labels
std::string getTypeName(); std::string getTypeName();
void dirtyNode(bool dirtyDescendents=true); void dirtyNode(bool dirtyDescendents=true);

View File

@@ -1,4 +1,6 @@
#include "Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetMenuBar.h" #include "Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetMenuBar.h"
#include "Engine/Network/NetworkManager.h"
#include "Engine/Operator/GeometryOperator.h"
#include <QLabel> #include <QLabel>
#include <qpainter.h> #include <qpainter.h>
#include <qpushbutton.h> #include <qpushbutton.h>
@@ -99,18 +101,19 @@ GeoSheetMenuBarModeSelection::GeoSheetMenuBarModeSelection(QWidget *parent, Qt::
modeButtonGroup_.setExclusive(true); modeButtonGroup_.setExclusive(true);
auto newButton = [this, &buttonBgLayout]() auto newButton = [this, &buttonBgLayout](const char* tooltip="")
{ {
auto newButton = new GeoSheetModeButton(); auto newButton = new GeoSheetModeButton();
newButton->setToolTip(tooltip);
modeButtonGroup_.addButton(newButton); modeButtonGroup_.addButton(newButton);
buttonBgLayout->addWidget(newButton); buttonBgLayout->addWidget(newButton);
return newButton; return newButton;
}; };
auto pointButton = newButton(); pointButton = newButton("Point Attributes");
auto vertButton = newButton(); vertexButton = newButton("Vertex Attributes");
auto primButton = newButton(); primitiveButton = newButton("Primitive Attributes");
auto globalButton = newButton(); globalButton = newButton("Global Attributes");
pointButton->setChecked(true); pointButton->setChecked(true);
@@ -121,12 +124,22 @@ GeoSheetMenuBarModeSelection::GeoSheetMenuBarModeSelection(QWidget *parent, Qt::
setLayout(mainLayout_); setLayout(mainLayout_);
} }
GeometrySpreadsheetMenuBar::GeometrySpreadsheetMenuBar(QWidget *parent, Qt::WindowFlags f) GeometrySpreadsheetMenuBar::GeometrySpreadsheetMenuBar(QWidget *parent, Qt::WindowFlags f)
: QWidget(parent, f) : QWidget(parent, f)
{ {
mainLayout_ = new QHBoxLayout(); mainLayout_ = new QHBoxLayout();
mainLayout_->addWidget(new QLabel("Node: testGeometryRat")); nodeLabel_ = new QLabel();
mainLayout_->addWidget(new GeoSheetMenuBarModeSelection()); mainLayout_->addWidget(nodeLabel_);
modeSelection = new GeoSheetMenuBarModeSelection();
mainLayout_->addWidget(modeSelection);
setLayout(mainLayout_); setLayout(mainLayout_);
} }
void GeometrySpreadsheetMenuBar::setNode(enzo::nt::OpId opId)
{
enzo::nt::GeometryOperator& geoOp = enzo::nt::nm().getGeoOperator(opId);
nodeLabel_->setText("Node: " + QString::fromStdString(geoOp.getLabel()));
}

View File

@@ -1,9 +1,12 @@
#pragma once #pragma once
#include "Engine/Operator/OpInfo.h"
#include "Engine/Types.h"
#include <QWidget> #include <QWidget>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <qbuttongroup.h> #include <qbuttongroup.h>
#include <qpushbutton.h> #include <qpushbutton.h>
#include <QLabel>
class GeoSheetModeButton class GeoSheetModeButton
: public QPushButton : public QPushButton
@@ -19,21 +22,30 @@ protected:
bool hovered_ = false; bool hovered_ = false;
}; };
class GeometrySpreadsheetMenuBar
: public QWidget
{
public:
GeometrySpreadsheetMenuBar(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
private:
QHBoxLayout* mainLayout_;
};
class GeoSheetMenuBarModeSelection class GeoSheetMenuBarModeSelection
: public QWidget : public QWidget
{ {
public: public:
GeoSheetMenuBarModeSelection(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); GeoSheetMenuBarModeSelection(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
GeoSheetModeButton* pointButton;
GeoSheetModeButton* vertexButton;
GeoSheetModeButton* primitiveButton;
GeoSheetModeButton* globalButton;
private: private:
QHBoxLayout* mainLayout_; QHBoxLayout* mainLayout_;
QButtonGroup modeButtonGroup_; QButtonGroup modeButtonGroup_;
}; };
class GeometrySpreadsheetMenuBar
: public QWidget
{
public:
GeometrySpreadsheetMenuBar(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
GeoSheetMenuBarModeSelection* modeSelection;
void setNode(enzo::nt::OpId opId);
private:
QHBoxLayout* mainLayout_;
QLabel* nodeLabel_;
};

View File

@@ -1,5 +1,4 @@
#include "Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.h" #include "Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.h"
#include "Engine/Network/NetworkManager.h"
#include "Engine/Operator/Attribute.h" #include "Engine/Operator/Attribute.h"
#include "Engine/Operator/AttributeHandle.h" #include "Engine/Operator/AttributeHandle.h"
#include "Engine/Operator/Geometry.h" #include "Engine/Operator/Geometry.h"
@@ -7,10 +6,11 @@
#include <icecream.hpp> #include <icecream.hpp>
#include <memory> #include <memory>
#include <stdexcept> #include <stdexcept>
#include <string>
GeometrySpreadsheetModel::GeometrySpreadsheetModel(const QStringList &strings, QObject *parent) GeometrySpreadsheetModel::GeometrySpreadsheetModel(QObject *parent)
: QAbstractListModel(parent), stringList(strings) : QAbstractListModel(parent)
{ {
} }
@@ -19,11 +19,18 @@ void GeometrySpreadsheetModel::geometryChanged(enzo::geo::Geometry& geometry)
{ {
beginResetModel(); beginResetModel();
geometry_ = geometry; geometry_ = geometry;
initBuffers();
endResetModel();
}
void GeometrySpreadsheetModel::initBuffers()
{
// get sizes // get sizes
const auto attribCount = geometry_.getNumAttributes(attributeOwner_); const auto attribCount = geometry_.getNumAttributes(attributeOwner_);
attribSizes_.clear(); attribSizes_.clear();
sectionAttribMap_.clear();
attribSizes_.reserve(attribCount); attribSizes_.reserve(attribCount);
for(size_t i=0; i<attribCount; ++i) for(size_t i=0; i<attribCount; ++i)
@@ -41,7 +48,14 @@ void GeometrySpreadsheetModel::geometryChanged(enzo::geo::Geometry& geometry)
} }
}
void GeometrySpreadsheetModel::setOwner(const enzo::ga::AttributeOwner owner)
{
beginResetModel();
attributeOwner_ = owner;
initBuffers();
endResetModel(); endResetModel();
} }
@@ -82,6 +96,8 @@ int GeometrySpreadsheetModel::columnCount(const QModelIndex &parent) const
return columnCount; return columnCount;
} }
QVariant GeometrySpreadsheetModel::data(const QModelIndex &index, int role) const QVariant GeometrySpreadsheetModel::data(const QModelIndex &index, int role) const
{ {
if (!index.isValid()) if (!index.isValid())
@@ -166,10 +182,30 @@ QVariant GeometrySpreadsheetModel::headerData(int section, Qt::Orientation orien
if (orientation == Qt::Horizontal) if (orientation == Qt::Horizontal)
{ {
if(auto attrib = geometry_.getAttributeByIndex(attributeOwner_, indexFromSection(section)).lock()) auto attributeIndex = indexFromSection(section);
if(auto attrib = geometry_.getAttributeByIndex(attributeOwner_, attributeIndex).lock())
{
if(attribSizes_[attributeIndex]>1)
{
const unsigned int valueIndex = section-attributeIndex;
std::string valueIndexString;
if(attrib->getType()==enzo::ga::AttrType::vectorT)
{
valueIndexString = std::array{".x", ".y", ".z", ".w"}.at(valueIndex);
}
else
{
valueIndexString = "["+std::to_string(valueIndex)+"]";
}
return QString::fromStdString(attrib->getName() + valueIndexString);
}
else
{ {
return QString::fromStdString(attrib->getName()); return QString::fromStdString(attrib->getName());
} }
}
else else
{ {
throw std::runtime_error("failed to lock attriubte index"); throw std::runtime_error("failed to lock attriubte index");

View File

@@ -9,7 +9,7 @@ class GeometrySpreadsheetModel : public QAbstractListModel
Q_OBJECT Q_OBJECT
public: public:
GeometrySpreadsheetModel(const QStringList &strings, QObject *parent = nullptr); GeometrySpreadsheetModel(QObject *parent = nullptr);
int rowCount(const QModelIndex &parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override;
@@ -19,14 +19,15 @@ public:
int indexFromSection(unsigned int section) const; int indexFromSection(unsigned int section) const;
void geometryChanged(enzo::geo::Geometry& geometry); void geometryChanged(enzo::geo::Geometry& geometry);
void setOwner(const enzo::ga::AttributeOwner owner);
void initBuffers();
private: private:
QStringList stringList;
enzo::nt::OpId opId_; enzo::nt::OpId opId_;
enzo::geo::Geometry geometry_; enzo::geo::Geometry geometry_;
std::vector<unsigned int> attribSizes_; std::vector<unsigned int> attribSizes_;
std::vector<unsigned int> sectionAttribMap_; std::vector<unsigned int> sectionAttribMap_;
enzo::ga::AttributeOwner attributeOwner_=enzo::ga::AttributeOwner::PRIMITIVE; enzo::ga::AttributeOwner attributeOwner_=enzo::ga::AttributeOwner::POINT;
}; };

View File

@@ -1,10 +1,12 @@
#include "Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetPanel.h" #include "Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetPanel.h"
#include "Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetMenuBar.h" #include "Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetMenuBar.h"
#include "Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.h" #include "Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.h"
#include "Engine/Network/NetworkManager.h"
#include <QTableWidget> #include <QTableWidget>
#include <QTreeWidget> #include <QTreeWidget>
#include <QLabel> #include <QLabel>
#include <qframe.h> #include <qframe.h>
#include <qpushbutton.h>
#include <qtablewidget.h> #include <qtablewidget.h>
#include <QPainterPath> #include <QPainterPath>
@@ -26,16 +28,31 @@ GeometrySpreadsheetPanel::GeometrySpreadsheetPanel(QWidget *parent, Qt::WindowFl
)"); )");
view_->setFrameStyle(QFrame::NoFrame); view_->setFrameStyle(QFrame::NoFrame);
model_ = new GeometrySpreadsheetModel({"hello", "world"}); model_ = new GeometrySpreadsheetModel();
view_->setModel(model_); view_->setModel(model_);
menuBar_ = new GeometrySpreadsheetMenuBar();
// connect buttons
connect(menuBar_->modeSelection->pointButton, &QPushButton::clicked, this, [this](){model_->setOwner(enzo::ga::AttributeOwner::POINT);});
connect(menuBar_->modeSelection->vertexButton, &QPushButton::clicked, this, [this](){model_->setOwner(enzo::ga::AttributeOwner::VERTEX);});
connect(menuBar_->modeSelection->primitiveButton, &QPushButton::clicked, this, [this](){model_->setOwner(enzo::ga::AttributeOwner::PRIMITIVE);});
connect(menuBar_->modeSelection->globalButton, &QPushButton::clicked, this, [this](){model_->setOwner(enzo::ga::AttributeOwner::GLOBAL);});
// set default
menuBar_->modeSelection->pointButton->click();
mainLayout_->addWidget(new GeometrySpreadsheetMenuBar());
mainLayout_->addWidget(menuBar_);
mainLayout_->addWidget(view_); mainLayout_->addWidget(view_);
setLayout(mainLayout_); setLayout(mainLayout_);
} }
void GeometrySpreadsheetPanel::setNode(enzo::nt::OpId opId)
{
menuBar_->setNode(opId);
}
void GeometrySpreadsheetPanel::geometryChanged(enzo::geo::Geometry& geometry) void GeometrySpreadsheetPanel::geometryChanged(enzo::geo::Geometry& geometry)
{ {
model_->geometryChanged(geometry); model_->geometryChanged(geometry);

View File

@@ -5,6 +5,7 @@
#include <qtreeview.h> #include <qtreeview.h>
#include "Engine/Types.h" #include "Engine/Types.h"
#include "Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.h" #include "Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.h"
#include "Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetMenuBar.h"
class GeometrySpreadsheetPanel class GeometrySpreadsheetPanel
: public QWidget : public QWidget
@@ -13,11 +14,13 @@ public:
GeometrySpreadsheetPanel(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); GeometrySpreadsheetPanel(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
public Q_SLOTS: public Q_SLOTS:
void geometryChanged(enzo::geo::Geometry& geometry); void geometryChanged(enzo::geo::Geometry& geometry);
void setNode(enzo::nt::OpId opId);
private: private:
QVBoxLayout* mainLayout_; QVBoxLayout* mainLayout_;
QWidget* bgWidget_; QWidget* bgWidget_;
GeometrySpreadsheetModel* model_; GeometrySpreadsheetModel* model_;
QTreeView* view_; QTreeView* view_;
GeometrySpreadsheetMenuBar* menuBar_;
protected: protected:
void resizeEvent(QResizeEvent *event) override; void resizeEvent(QResizeEvent *event) override;

View File

@@ -63,6 +63,7 @@ EnzoUI::EnzoUI()
// connect signals // connect signals
enzo::nt::nm().displayNodeChanged.connect([parametersPanel](enzo::nt::OpId opId){parametersPanel->selectionChanged(opId);}); enzo::nt::nm().displayNodeChanged.connect([parametersPanel](enzo::nt::OpId opId){parametersPanel->selectionChanged(opId);});
enzo::nt::nm().displayNodeChanged.connect([geometrySpreadsheetPanel](enzo::nt::OpId opId){geometrySpreadsheetPanel->setNode(opId);});
enzo::nt::nm().displayGeoChanged.connect([geometrySpreadsheetPanel](enzo::geo::Geometry& geometry){geometrySpreadsheetPanel->geometryChanged(geometry);}); enzo::nt::nm().displayGeoChanged.connect([geometrySpreadsheetPanel](enzo::geo::Geometry& geometry){geometrySpreadsheetPanel->geometryChanged(geometry);});
enzo::nt::nm().displayGeoChanged.connect([viewport](enzo::geo::Geometry& geometry){viewport->setGeometry(geometry);}); enzo::nt::nm().displayGeoChanged.connect([viewport](enzo::geo::Geometry& geometry){viewport->setGeometry(geometry);});
} }