Skip to content
Snippets Groups Projects
Commit 3bcfe4a6 authored by Lars Bilke's avatar Lars Bilke
Browse files

Merge pull request #1112 from rinkk/MshModelMemSave

Static string references for MshModel
parents 99fee93e 11e7ebac
No related branches found
No related tags found
No related merge requests found
......@@ -32,13 +32,15 @@
#include "Elements/Element.h"
#include "MeshEnums.h"
const QVariant MshModel::element_str = "Element";
const std::map<MeshLib::MeshElemType, QVariant> MshModel::elem_type_map = MshModel::createMeshElemTypeMap();
MshModel::MshModel(ProjectData &project, QObject* parent /*= 0*/ )
: TreeModel(parent), _project(project)
{
delete _rootItem;
QList<QVariant> rootData;
rootData << "Mesh Name" << "Type" << "Node IDs";
rootData << "Mesh Name" << "#" << "Type";
_rootItem = new TreeItem(rootData, nullptr);
}
......@@ -46,7 +48,7 @@ int MshModel::columnCount( const QModelIndex &parent /*= QModelIndex()*/ ) const
{
Q_UNUSED(parent)
return 2;
return 3;
}
void MshModel::addMesh(MeshLib::Mesh* mesh)
......@@ -58,31 +60,21 @@ void MshModel::addMesh(MeshLib::Mesh* mesh)
void MshModel::addMeshObject(const MeshLib::Mesh* mesh)
{
INFO("name: %s", mesh->getName().c_str());
QString display_name (QString::fromStdString(mesh->getName()));
QVariant const display_name (QString::fromStdString(mesh->getName()));
QList<QVariant> meshData;
meshData << display_name << "";
MshItem* newMesh = new MshItem(meshData, _rootItem, mesh);
meshData << display_name << "" << "";
MshItem *const newMesh = new MshItem(meshData, _rootItem, mesh);
_rootItem->appendChild(newMesh);
// display elements
const std::vector<MeshLib::Element*> &elems = mesh->getElements();
const std::size_t nElems (elems.size());
QString elem_type_string("");
MeshLib::MeshElemType elem_type(MeshLib::MeshElemType::INVALID);
std::vector<MeshLib::Element*> const& elems = mesh->getElements();
int const nElems (static_cast<int>(elems.size()));
for (std::size_t i = 0; i < nElems; i++)
for (int i = 0; i < nElems; i++)
{
const MeshLib::Element* current_element (elems[i]);
MeshLib::MeshElemType t (current_element->getGeomType());
QList<QVariant> elemData;
elemData.reserve(3);
if (t != elem_type)
{
elem_type = t;
elem_type_string = QString::fromStdString(MeshElemType2String(t));
}
elemData << "Element " + QString::number(i) << elem_type_string;
elemData << element_str << i << elem_type_map.at(elems[i]->getGeomType());
newMesh->appendChild(new TreeItem(elemData, newMesh));
}
......@@ -168,6 +160,17 @@ void MshModel::updateModel()
addMeshObject(*it);
}
std::map<MeshLib::MeshElemType, QVariant> MshModel::createMeshElemTypeMap()
{
std::vector<MeshLib::MeshElemType> const& elem_types (MeshLib::getMeshElemTypes());
std::map<MeshLib::MeshElemType, QVariant> elem_map;
for (MeshLib::MeshElemType t : elem_types)
elem_map[t] = QVariant(QString::fromStdString(MeshLib::MeshElemType2String(t)));
return elem_map;
}
vtkUnstructuredGridAlgorithm* MshModel::vtkSource(const QModelIndex &idx) const
{
if (idx.isValid())
......
......@@ -69,6 +69,12 @@ private:
//bool isUniqueMeshName(std::string &name);
ProjectData& _project;
/// Creates a static map of all element type name-strings in QVariant format
static std::map<MeshLib::MeshElemType, QVariant> createMeshElemTypeMap();
static const std::map<MeshLib::MeshElemType, QVariant> elem_type_map;
static const QVariant element_str;
signals:
void meshAdded(MshModel*, const QModelIndex&);
void meshRemoved(MshModel*, const QModelIndex&);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment