diff --git a/src/Engine/Operator/Attribute.cpp b/src/Engine/Operator/Attribute.cpp index bfbd264..9849f19 100644 --- a/src/Engine/Operator/Attribute.cpp +++ b/src/Engine/Operator/Attribute.cpp @@ -73,7 +73,7 @@ ga::Attribute::Attribute(const Attribute& other) } -ga::AttributeType ga::Attribute::getType() +ga::AttributeType ga::Attribute::getType() const { return type_; } diff --git a/src/Engine/Operator/Attribute.h b/src/Engine/Operator/Attribute.h index 4a7bdb2..23eb096 100644 --- a/src/Engine/Operator/Attribute.h +++ b/src/Engine/Operator/Attribute.h @@ -21,7 +21,7 @@ namespace enzo{ public: Attribute(std::string name, ga::AttributeType type); Attribute(const Attribute& other); - AttributeType getType(); + AttributeType getType() const; std::string getName() const; unsigned int getTypeSize() const; @@ -29,6 +29,8 @@ namespace enzo{ template friend class AttributeHandle; + template + friend class AttributeHandleRO; private: // private attributes are attributes that are hidden from the user diff --git a/src/Engine/Operator/AttributeHandle.h b/src/Engine/Operator/AttributeHandle.h index 5f0909a..6f67901 100644 --- a/src/Engine/Operator/AttributeHandle.h +++ b/src/Engine/Operator/AttributeHandle.h @@ -51,8 +51,8 @@ public: { throw std::runtime_error("Type " + std::to_string(static_cast(type_)) + " was not properly accounted for in AttributeHandle constructor"); } - } + void addValue(T value) { // TODO:make this private (primitive friend classes only) @@ -119,4 +119,94 @@ using AttributeHandleFloat = AttributeHandle; using AttributeHandleVector3 = AttributeHandle; using AttributeHandleBool = AttributeHandle; +template +class AttributeHandleRO +{ +public: + ga::AttributeType type_; + + AttributeHandleRO(std::shared_ptr attribute) + { + type_ = attribute->getType(); + // get attribute data pointer + // TODO: check types match + // TODO: add the other types + + // int + if constexpr (std::is_same::value) + { + data_=attribute->intStore_; + } + + // float + else if constexpr (std::is_same::value) + { + data_=attribute->floatStore_; + } + + // vector 3 + else if constexpr (std::is_same::value) + { + data_=attribute->vector3Store_; + } + else if constexpr (std::is_same::value) + { + data_=attribute->boolStore_; + } + else + { + throw std::runtime_error("Type " + std::to_string(static_cast(type_)) + " was not properly accounted for in AttributeHandle constructor"); + } + + } + + // TODO: replace with iterator + std::vector getAllValues() const + { + return {data_->begin(), data_->end()}; + } + + size_t getSize() const + { + return data_->size(); + } + + T getValue(size_t pos) const + { + // TODO:protect against invalid positions + // TODO: cast types + return (*data_)[pos]; + } + + std::string getName() const + { + return name_; + } + + + +private: + // private attributes are attributes that are hidden from the user + // for internal use + bool private_=false; + // hidden attributes are user accessible attributes that the user may + // or may want to use + bool hidden_=false; + // allows the user to read the attributeHandle but not modify it + bool readOnly_=false; + + std::string name_=""; + + std::shared_ptr> data_; + + // int typeID_; + +}; + +using AttributeHandleInt = AttributeHandle; +using AttributeHandleFloat = AttributeHandle; +using AttributeHandleVector3 = AttributeHandle; +using AttributeHandleBool = AttributeHandle; + + } diff --git a/src/Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.cpp b/src/Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.cpp index fff71d8..80a5280 100644 --- a/src/Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.cpp +++ b/src/Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.cpp @@ -1,6 +1,7 @@ #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" #include "Engine/Types.h" #include @@ -17,19 +18,17 @@ GeometrySpreadsheetModel::GeometrySpreadsheetModel(const QStringList &strings, Q void GeometrySpreadsheetModel::geometryChanged(enzo::geo::Geometry& geometry) { beginResetModel(); - // enzo::nt::NetworkManager& nm = enzo::nt::nm(); - IC(); geometry_ = geometry; // get sizes - const auto attribCount = geometry_.getNumAttributes(enzo::ga::AttributeOwner::POINT); + const auto attribCount = geometry_.getNumAttributes(attributeOwner_); attribSizes_.clear(); attribSizes_.reserve(attribCount); for(size_t i=0; igetTypeSize(); attribSizes_.push_back(size); @@ -48,7 +47,27 @@ void GeometrySpreadsheetModel::geometryChanged(enzo::geo::Geometry& geometry) int GeometrySpreadsheetModel::rowCount(const QModelIndex &parent) const { - return geometry_.getNumPoints(); + switch(attributeOwner_) + { + case enzo::ga::AttributeOwner::POINT: + { + return geometry_.getNumPoints(); + } + case enzo::ga::AttributeOwner::VERTEX: + { + return geometry_.getNumVerts(); + } + case enzo::ga::AttributeOwner::PRIMITIVE: + { + return geometry_.getNumPrims(); + } + case enzo::ga::AttributeOwner::GLOBAL: + { + return 1; + } + + } + return 1; } int GeometrySpreadsheetModel::columnCount(const QModelIndex &parent) const @@ -70,15 +89,57 @@ QVariant GeometrySpreadsheetModel::data(const QModelIndex &index, int role) cons return QVariant(); } - if (index.row() >= geometry_.getNumPoints()) - { - return QVariant(); - } + // TODO: reimplement check + // if (index.row() >= geometry_.getNumPoints()) + // { + // return QVariant(); + // } if (role == Qt::DisplayRole) { - std::cout << geometry_.getPointPos(index.row()).x() << "\n"; - return geometry_.getPointPos(index.row()).x(); + + // std::cout << geometry_.getPointPos(index.row()).x() << "\n"; + int attributeIndex = indexFromSection(index.column()); + if(std::shared_ptr attrib = geometry_.getAttributeByIndex(attributeOwner_, attributeIndex).lock()) + { + const unsigned int valueIndex = index.column()-attributeIndex; + using namespace enzo::ga; + + switch(attrib->getType()) + { + case(AttributeType::intT): + { + const auto attribHandle = enzo::ga::AttributeHandleRO(attrib); + return static_cast(attribHandle.getValue(index.row())); + } + case(AttributeType::floatT): + { + const auto attribHandle = enzo::ga::AttributeHandleRO(attrib); + return attribHandle.getValue(index.row()); + } + case(AttributeType::boolT): + { + const auto attribHandle = enzo::ga::AttributeHandleRO(attrib); + return attribHandle.getValue(index.row()) ? "true" : "false"; + } + case(AttributeType::vectorT): + { + const auto attribHandle = enzo::ga::AttributeHandleRO(attrib); + return attribHandle.getValue(index.row())[valueIndex]; + } + default: + { + return "Failed"; + break; + } + + } + } + else + { + throw std::runtime_error("Couldn't lock attribute"); + } + // return geometry_.getPointPos(index.row()).x(); } else { @@ -105,7 +166,7 @@ QVariant GeometrySpreadsheetModel::headerData(int section, Qt::Orientation orien if (orientation == Qt::Horizontal) { - if(auto attrib = geometry_.getAttributeByIndex(enzo::ga::AttributeOwner::POINT, indexFromSection(section)).lock()) + if(auto attrib = geometry_.getAttributeByIndex(attributeOwner_, indexFromSection(section)).lock()) { return QString::fromStdString(attrib->getName()); } diff --git a/src/Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.h b/src/Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.h index 65f2e98..e067017 100644 --- a/src/Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.h +++ b/src/Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.h @@ -27,5 +27,6 @@ private: enzo::geo::Geometry geometry_; std::vector attribSizes_; std::vector sectionAttribMap_; + enzo::ga::AttributeOwner attributeOwner_=enzo::ga::AttributeOwner::PRIMITIVE; }; diff --git a/src/Gui/Interface.cpp b/src/Gui/Interface.cpp index c3873fa..e640d18 100644 --- a/src/Gui/Interface.cpp +++ b/src/Gui/Interface.cpp @@ -53,7 +53,7 @@ EnzoUI::EnzoUI() viewportSplitter_->addWidget(spreadsheetSplitter_); viewportSplitter_->addWidget(networkSplitter_); - viewportSplitter_->setSizes({100,100}); + viewportSplitter_->setSizes({100,300}); networkSplitter_->addWidget(parametersPanel); networkSplitter_->addWidget(network);