Commit 0728f615 authored by Tom Fischer's avatar Tom Fischer
Browse files

[GL] Make geoPointsToStations a free function.

parent c7a1a429
......@@ -1335,7 +1335,8 @@ void MainWindow::showMeshAnalysisDialog()
void MainWindow::convertPointsToStations(std::string const& geo_name)
{
std::string stn_name = geo_name + " Stations";
int ret = _project.getGEOObjects().geoPointsToStations(geo_name, stn_name);
int ret = GeoLib::geoPointsToStations(_project.getGEOObjects(), geo_name,
stn_name);
if (ret == 1)
{
OGSError::box("No points found to convert.");
......
......@@ -693,11 +693,10 @@ void markUnusedPoints(GEOObjects const& geo_objects,
}
}
int GEOObjects::geoPointsToStations(std::string const& geo_name,
std::string& stn_name,
bool const only_unused_pnts)
int geoPointsToStations(GEOObjects& geo_objects, std::string const& geo_name,
std::string& stn_name, bool const only_unused_pnts)
{
GeoLib::PointVec const* const pnt_obj(getPointVecObj(geo_name));
GeoLib::PointVec const* const pnt_obj(geo_objects.getPointVecObj(geo_name));
if (pnt_obj == nullptr)
{
ERR("Point vector {:s} not found.", geo_name);
......@@ -713,7 +712,7 @@ int GEOObjects::geoPointsToStations(std::string const& geo_name,
std::vector<bool> transfer_pnts(n_pnts, true);
if (only_unused_pnts)
{
markUnusedPoints(*this, geo_name, transfer_pnts);
markUnusedPoints(geo_objects, geo_name, transfer_pnts);
}
auto stations = std::make_unique<std::vector<GeoLib::Point*>>();
......@@ -732,7 +731,7 @@ int GEOObjects::geoPointsToStations(std::string const& geo_name,
}
if (!stations->empty())
{
addStationVec(std::move(stations), stn_name);
geo_objects.addStationVec(std::move(stations), stn_name);
}
else
{
......
......@@ -253,15 +253,6 @@ public:
void renameGeometry(std::string const& old_name,
std::string const& new_name);
/// Constructs a station-vector based on the points of a given geometry.
// @param geo_name name of the geometry
// @param stn_name name of the new station vector
// @param only_usused_pnts if true only points not in a line or surface are
// transferred, otherwise all points
int geoPointsToStations(std::string const& geo_name,
std::string& stn_name,
bool const only_unused_pnts = true);
/// Returns the geo object for a geometric item of the given name and type for the associated geometry.
const GeoLib::GeoObject* getGeoObject(const std::string &geo_name,
GeoLib::GEOTYPE type,
......@@ -372,4 +363,15 @@ private:
std::string const& merged_geo_name,
std::vector<std::size_t> const& pnt_offsets);
};
/// Constructs a station-vector based on the points of a given geometry.
// @param geo_obj geometry manager object
// @param geo_name name of the geometry
// @param stn_name name of the new station vector
// @param only_usused_pnts if true only points not in a line or surface are
// transferred, otherwise all points
int geoPointsToStations(GEOObjects& geo_objects, std::string const& geo_name,
std::string& stn_name,
bool const only_unused_pnts = true);
} // namespace GeoLib
/**
* \file
* \brief Tests for GeoLib::GEOOnjects::geoPointsToStations()
* \brief Tests for geoPointsToStations()
*
* \copyright
* Copyright (c) 2012-2021, OpenGeoSys Community (http://www.opengeosys.org)
......@@ -33,7 +33,7 @@ TEST(GeoLib, PointToStationConversion)
// converting only unused points
std::string stn_orphaned_pnts("Orphaned Points");
int const res_orphaned_pnts =
geo_obj.geoPointsToStations(geo_name, stn_orphaned_pnts, true);
geoPointsToStations(geo_obj, geo_name, stn_orphaned_pnts, true);
EXPECT_EQ(0, res_orphaned_pnts);
auto const* const stns = geo_obj.getStationVec(stn_orphaned_pnts);
assert(stns != nullptr);
......@@ -49,7 +49,7 @@ TEST(GeoLib, PointToStationConversion)
// converting all points
std::string stn_all_pnts("All Points");
int const res_all_pnts =
geo_obj.geoPointsToStations(geo_name, stn_all_pnts, false);
geoPointsToStations(geo_obj, geo_name, stn_all_pnts, false);
EXPECT_EQ(0, res_all_pnts);
EXPECT_EQ(exp_all_pnts, geo_obj.getStationVec(stn_all_pnts)->size());
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment