Skip to content
Snippets Groups Projects
Commit 4b245f99 authored by Karsten Rink's avatar Karsten Rink
Browse files

created new data container object for GUI

parent b8909bfb
No related branches found
No related tags found
No related merge requests found
# Source files
GET_SOURCE_FILES(SOURCES_DataHolderLib)
# Library
add_library(DataHolderLib ${SOURCES_DataHolderLib})
target_link_libraries(DataHolderLib
GeoLib
MeshLib
logog
)
\ No newline at end of file
/**
* \copyright
* Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#include "DataExplorerProject.h"
#include <algorithm>
// ThirdParty/logog
#include "logog/include/logog.hpp"
#include "BaseLib/FileTools.h"
#include "BaseLib/uniqueInsert.h"
#include "MeshLib/Mesh.h"
DataExplorerProject::DataExplorerProject() = default;
DataExplorerProject::~DataExplorerProject()
{
delete _geoObjects;
for (MeshLib::Mesh* m : _mesh_vec)
delete m;
}
void DataExplorerProject::addMesh(MeshLib::Mesh* mesh)
{
std::string name = mesh->getName();
isMeshNameUniqueAndProvideUniqueName(name);
mesh->setName(name);
_mesh_vec.push_back(mesh);
}
std::vector<MeshLib::Mesh*>::const_iterator DataExplorerProject::findMeshByName(
std::string const& name) const
{
return const_cast<DataExplorerProject&>(*this).findMeshByName(name);
}
std::vector<MeshLib::Mesh*>::iterator DataExplorerProject::findMeshByName(
std::string const& name)
{
return std::find_if(_mesh_vec.begin(), _mesh_vec.end(),
[&name](MeshLib::Mesh* mesh)
{
return mesh && (name == mesh->getName());
});
}
const MeshLib::Mesh* DataExplorerProject::getMesh(const std::string &name) const
{
std::vector<MeshLib::Mesh*>::const_iterator it = findMeshByName(name);
return (it == _mesh_vec.end() ? nullptr : *it);
}
bool DataExplorerProject::removeMesh(const std::string &name)
{
bool mesh_found = false;
std::vector<MeshLib::Mesh*>::iterator it = findMeshByName(name);
while (it != _mesh_vec.end())
{
delete *it;
*it = nullptr;
it = findMeshByName(name);
mesh_found = true;
}
_mesh_vec.erase(std::remove(_mesh_vec.begin(), _mesh_vec.end(), nullptr),
_mesh_vec.end());
return mesh_found;
}
bool DataExplorerProject::meshExists(const std::string &name) const
{
return findMeshByName(name) != _mesh_vec.end();
}
bool DataExplorerProject::isMeshNameUniqueAndProvideUniqueName(std::string &name) const
{
int count(0);
bool isUnique(false);
std::string cpName;
while (!isUnique)
{
isUnique = true;
cpName = name;
count++;
// If the original name already exists we start to add numbers to name for
// as long as it takes to make the name unique.
if (count > 1)
cpName = cpName + "-" + std::to_string(count);
for (std::vector<MeshLib::Mesh*>::const_iterator it = _mesh_vec.begin();
it != _mesh_vec.end(); ++it)
if ( cpName.compare((*it)->getName()) == 0 )
isUnique = false;
}
// At this point cpName is a unique name and isUnique is true.
// If cpName is not the original name, "name" is changed and isUnique is set to false,
// indicating that a vector with the original name already exists.
if (count > 1)
{
isUnique = false;
name = cpName;
}
return isUnique;
}
/**
* \copyright
* Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#ifndef DATAEXPLORERPROJECT_H_
#define DATAEXPLORERPROJECT_H_
#include <memory>
#include "GeoLib/GEOObjects.h"
namespace MeshLib {
class Mesh;
}
/**
* The ProjectData Object contains all the data needed for a certain project, i.e. all
* geometric data (stored in a GEOObjects-object), all the meshes, processes,
* and process variables.
*/
class DataExplorerProject final
{
public:
/// Constructor
DataExplorerProject();
DataExplorerProject(DataExplorerProject&) = delete;
~DataExplorerProject();
/// Returns the GEOObjects containing all points, polylines and surfaces.
GeoLib::GEOObjects* getGEOObjects()
{
return _geoObjects;
}
/// Adds a new mesh under a (possibly new) unique name.
/// \attention This might change the given mesh's name.
void addMesh(MeshLib::Mesh* mesh);
/// Returns the mesh with the given name or a \c nullptr if the mesh was not
/// found.
const MeshLib::Mesh* getMesh(const std::string &name) const;
/// Returns all the meshes with their respective names
const std::vector<MeshLib::Mesh*>& getMeshObjects() const
{
return _mesh_vec;
}
/// Deletes all meshes with the given name and removes them from the list of
/// saved meshes. If any mesh was found for removal, true is returned and
/// false otherwise.
bool removeMesh(const std::string &name);
private:
/// Checks if a mesh with the same name exists and provides a unique name in
/// case of already existing mesh. Returns true if the mesh name is unique.
/// Returns false and changes the provided name to a unique name otherwise.
bool isMeshNameUniqueAndProvideUniqueName(std::string &name) const;
/// Returns true if a mesh with the same name exists and false otherwise.
bool meshExists(const std::string &name) const;
/// Returns an iterator to the first found mesh with the given name.
std::vector<MeshLib::Mesh*>::const_iterator findMeshByName(
std::string const& name) const;
std::vector<MeshLib::Mesh*>::iterator findMeshByName(
std::string const& name);
GeoLib::GEOObjects *_geoObjects = new GeoLib::GEOObjects();
std::vector<MeshLib::Mesh*> _mesh_vec;
};
#endif //DATAEXPLORERPROJECT_H_
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