feat(geometrySpreadsheet): connect attribute buttons
This commit is contained in:
@@ -124,6 +124,12 @@ std::vector<std::weak_ptr<prm::Parameter>> nt::GeometryOperator::getParameters()
|
||||
return {parameters_.begin(), parameters_.end()};
|
||||
}
|
||||
|
||||
std::string nt::GeometryOperator::getLabel()
|
||||
{
|
||||
return getTypeName();
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::weak_ptr<const nt::GeometryConnection>> nt::GeometryOperator::getOutputConnections() const
|
||||
{
|
||||
return {outputConnections_.begin(), outputConnections_.end()};
|
||||
|
||||
@@ -30,6 +30,7 @@ public:
|
||||
std::vector<std::weak_ptr<prm::Parameter>> getParameters();
|
||||
std::weak_ptr<prm::Parameter> getParameter(std::string parameterName);
|
||||
|
||||
std::string getLabel(); // TODO: implement node labels
|
||||
std::string getTypeName();
|
||||
|
||||
void dirtyNode(bool dirtyDescendents=true);
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include "Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetMenuBar.h"
|
||||
#include "Engine/Network/NetworkManager.h"
|
||||
#include "Engine/Operator/GeometryOperator.h"
|
||||
#include <QLabel>
|
||||
#include <qpainter.h>
|
||||
#include <qpushbutton.h>
|
||||
@@ -99,18 +101,19 @@ GeoSheetMenuBarModeSelection::GeoSheetMenuBarModeSelection(QWidget *parent, Qt::
|
||||
|
||||
modeButtonGroup_.setExclusive(true);
|
||||
|
||||
auto newButton = [this, &buttonBgLayout]()
|
||||
auto newButton = [this, &buttonBgLayout](const char* tooltip="")
|
||||
{
|
||||
auto newButton = new GeoSheetModeButton();
|
||||
newButton->setToolTip(tooltip);
|
||||
modeButtonGroup_.addButton(newButton);
|
||||
buttonBgLayout->addWidget(newButton);
|
||||
return newButton;
|
||||
};
|
||||
|
||||
auto pointButton = newButton();
|
||||
auto vertButton = newButton();
|
||||
auto primButton = newButton();
|
||||
auto globalButton = newButton();
|
||||
pointButton = newButton("Point Attributes");
|
||||
vertexButton = newButton("Vertex Attributes");
|
||||
primitiveButton = newButton("Primitive Attributes");
|
||||
globalButton = newButton("Global Attributes");
|
||||
|
||||
pointButton->setChecked(true);
|
||||
|
||||
@@ -121,12 +124,22 @@ GeoSheetMenuBarModeSelection::GeoSheetMenuBarModeSelection(QWidget *parent, Qt::
|
||||
setLayout(mainLayout_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
GeometrySpreadsheetMenuBar::GeometrySpreadsheetMenuBar(QWidget *parent, Qt::WindowFlags f)
|
||||
: QWidget(parent, f)
|
||||
{
|
||||
mainLayout_ = new QHBoxLayout();
|
||||
mainLayout_->addWidget(new QLabel("Node: testGeometryRat"));
|
||||
mainLayout_->addWidget(new GeoSheetMenuBarModeSelection());
|
||||
nodeLabel_ = new QLabel();
|
||||
mainLayout_->addWidget(nodeLabel_);
|
||||
modeSelection = new GeoSheetMenuBarModeSelection();
|
||||
mainLayout_->addWidget(modeSelection);
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "Engine/Operator/OpInfo.h"
|
||||
#include "Engine/Types.h"
|
||||
#include <QWidget>
|
||||
#include <QHBoxLayout>
|
||||
#include <qbuttongroup.h>
|
||||
#include <qpushbutton.h>
|
||||
#include <QLabel>
|
||||
|
||||
class GeoSheetModeButton
|
||||
: public QPushButton
|
||||
@@ -19,21 +22,30 @@ protected:
|
||||
bool hovered_ = false;
|
||||
};
|
||||
|
||||
class GeometrySpreadsheetMenuBar
|
||||
: public QWidget
|
||||
{
|
||||
public:
|
||||
GeometrySpreadsheetMenuBar(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
|
||||
private:
|
||||
QHBoxLayout* mainLayout_;
|
||||
};
|
||||
|
||||
class GeoSheetMenuBarModeSelection
|
||||
: public QWidget
|
||||
{
|
||||
public:
|
||||
GeoSheetMenuBarModeSelection(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
|
||||
|
||||
GeoSheetModeButton* pointButton;
|
||||
GeoSheetModeButton* vertexButton;
|
||||
GeoSheetModeButton* primitiveButton;
|
||||
GeoSheetModeButton* globalButton;
|
||||
private:
|
||||
QHBoxLayout* mainLayout_;
|
||||
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_;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.h"
|
||||
#include "Engine/Network/NetworkManager.h"
|
||||
#include "Engine/Operator/Attribute.h"
|
||||
#include "Engine/Operator/AttributeHandle.h"
|
||||
#include "Engine/Operator/Geometry.h"
|
||||
@@ -7,10 +6,11 @@
|
||||
#include <icecream.hpp>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
|
||||
GeometrySpreadsheetModel::GeometrySpreadsheetModel(const QStringList &strings, QObject *parent)
|
||||
: QAbstractListModel(parent), stringList(strings)
|
||||
GeometrySpreadsheetModel::GeometrySpreadsheetModel(QObject *parent)
|
||||
: QAbstractListModel(parent)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -19,11 +19,18 @@ void GeometrySpreadsheetModel::geometryChanged(enzo::geo::Geometry& geometry)
|
||||
{
|
||||
beginResetModel();
|
||||
geometry_ = geometry;
|
||||
initBuffers();
|
||||
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void GeometrySpreadsheetModel::initBuffers()
|
||||
{
|
||||
// get sizes
|
||||
const auto attribCount = geometry_.getNumAttributes(attributeOwner_);
|
||||
|
||||
attribSizes_.clear();
|
||||
sectionAttribMap_.clear();
|
||||
attribSizes_.reserve(attribCount);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -82,6 +96,8 @@ int GeometrySpreadsheetModel::columnCount(const QModelIndex &parent) const
|
||||
return columnCount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
QVariant GeometrySpreadsheetModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
@@ -166,9 +182,29 @@ QVariant GeometrySpreadsheetModel::headerData(int section, Qt::Orientation orien
|
||||
|
||||
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())
|
||||
{
|
||||
return QString::fromStdString(attrib->getName());
|
||||
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());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ class GeometrySpreadsheetModel : public QAbstractListModel
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GeometrySpreadsheetModel(const QStringList &strings, QObject *parent = nullptr);
|
||||
GeometrySpreadsheetModel(QObject *parent = nullptr);
|
||||
|
||||
int rowCount(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;
|
||||
|
||||
void geometryChanged(enzo::geo::Geometry& geometry);
|
||||
void setOwner(const enzo::ga::AttributeOwner owner);
|
||||
void initBuffers();
|
||||
|
||||
|
||||
private:
|
||||
QStringList stringList;
|
||||
enzo::nt::OpId opId_;
|
||||
enzo::geo::Geometry geometry_;
|
||||
std::vector<unsigned int> attribSizes_;
|
||||
std::vector<unsigned int> sectionAttribMap_;
|
||||
enzo::ga::AttributeOwner attributeOwner_=enzo::ga::AttributeOwner::PRIMITIVE;
|
||||
enzo::ga::AttributeOwner attributeOwner_=enzo::ga::AttributeOwner::POINT;
|
||||
|
||||
};
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#include "Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetPanel.h"
|
||||
#include "Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetMenuBar.h"
|
||||
#include "Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.h"
|
||||
#include "Engine/Network/NetworkManager.h"
|
||||
#include <QTableWidget>
|
||||
#include <QTreeWidget>
|
||||
#include <QLabel>
|
||||
#include <qframe.h>
|
||||
#include <qpushbutton.h>
|
||||
#include <qtablewidget.h>
|
||||
#include <QPainterPath>
|
||||
|
||||
@@ -26,16 +28,31 @@ GeometrySpreadsheetPanel::GeometrySpreadsheetPanel(QWidget *parent, Qt::WindowFl
|
||||
)");
|
||||
view_->setFrameStyle(QFrame::NoFrame);
|
||||
|
||||
model_ = new GeometrySpreadsheetModel({"hello", "world"});
|
||||
model_ = new GeometrySpreadsheetModel();
|
||||
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_);
|
||||
|
||||
setLayout(mainLayout_);
|
||||
}
|
||||
|
||||
void GeometrySpreadsheetPanel::setNode(enzo::nt::OpId opId)
|
||||
{
|
||||
menuBar_->setNode(opId);
|
||||
}
|
||||
|
||||
|
||||
void GeometrySpreadsheetPanel::geometryChanged(enzo::geo::Geometry& geometry)
|
||||
{
|
||||
model_->geometryChanged(geometry);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <qtreeview.h>
|
||||
#include "Engine/Types.h"
|
||||
#include "Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.h"
|
||||
#include "Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetMenuBar.h"
|
||||
|
||||
class GeometrySpreadsheetPanel
|
||||
: public QWidget
|
||||
@@ -13,11 +14,13 @@ public:
|
||||
GeometrySpreadsheetPanel(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
|
||||
public Q_SLOTS:
|
||||
void geometryChanged(enzo::geo::Geometry& geometry);
|
||||
void setNode(enzo::nt::OpId opId);
|
||||
private:
|
||||
QVBoxLayout* mainLayout_;
|
||||
QWidget* bgWidget_;
|
||||
GeometrySpreadsheetModel* model_;
|
||||
QTreeView* view_;
|
||||
GeometrySpreadsheetMenuBar* menuBar_;
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ EnzoUI::EnzoUI()
|
||||
|
||||
// connect signals
|
||||
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([viewport](enzo::geo::Geometry& geometry){viewport->setGeometry(geometry);});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user