From 565904fb0f88c9744330fc6c710c0ff792fd9e7e Mon Sep 17 00:00:00 2001 From: rinkk <karsten.rink@ufz.de> Date: Tue, 19 Feb 2019 12:41:24 +0100 Subject: [PATCH] renaming variables & methods and fixing const issues --- Applications/DataExplorer/mainwindow.cpp | 4 ++- GeoLib/GEOObjects.cpp | 40 +++++++++++++----------- GeoLib/GEOObjects.h | 10 +++--- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/Applications/DataExplorer/mainwindow.cpp b/Applications/DataExplorer/mainwindow.cpp index d3c3ff9df54..40301224b46 100644 --- a/Applications/DataExplorer/mainwindow.cpp +++ b/Applications/DataExplorer/mainwindow.cpp @@ -1102,7 +1102,9 @@ void MainWindow::showMeshAnalysisDialog() void MainWindow::convertPointsToStations(std::string const& geo_name) { std::string const stn_name = geo_name + "Stations"; - _project.getGEOObjects().geoPointsToStation(geo_name, stn_name); + int ret = _project.getGEOObjects().geoPointsToStation(geo_name, stn_name); + if (ret == 1) + OGSError::box("No points found to convert."); } void MainWindow::showLineEditDialog(const std::string &geoName) diff --git a/GeoLib/GEOObjects.cpp b/GeoLib/GEOObjects.cpp index fb6b4856160..a0ec2474587 100644 --- a/GeoLib/GEOObjects.cpp +++ b/GeoLib/GEOObjects.cpp @@ -554,18 +554,18 @@ void GEOObjects::renameGeometry(std::string const& old_name, } } -void GEOObjects::markPointsAsUsed(std::string const& geo_name, - std::vector<bool>& flags) +void GEOObjects::markUnusedPoints(std::string const& geo_name, + std::vector<bool>& transfer_pnts) const { GeoLib::PolylineVec const* const ply_obj(getPolylineVecObj(geo_name)); if (ply_obj) { std::vector<GeoLib::Polyline*> const& lines(*ply_obj->getVector()); - for (auto line : lines) + for (auto* line : lines) { std::size_t const n_pnts(line->getNumberOfPoints()); for (std::size_t i = 0; i < n_pnts; ++i) - flags[line->getPointID(i)] = false; + transfer_pnts[line->getPointID(i)] = false; } } @@ -573,58 +573,60 @@ void GEOObjects::markPointsAsUsed(std::string const& geo_name, if (sfc_obj) { std::vector<GeoLib::Surface*> const& surfaces = *sfc_obj->getVector(); - for (auto sfc : surfaces) + for (auto* sfc : surfaces) { std::size_t const n_tri(sfc->getNumberOfTriangles()); for (std::size_t i = 0; i < n_tri; ++i) { GeoLib::Triangle const& t = *(*sfc)[i]; - flags[t[0]] = false; - flags[t[1]] = false; - flags[t[2]] = false; + transfer_pnts[t[0]] = false; + transfer_pnts[t[1]] = false; + transfer_pnts[t[2]] = false; } } } } -void GEOObjects::geoPointsToStation(std::string const& geo_name, +int GEOObjects::geoPointsToStation(std::string const& geo_name, std::string const& stn_name, - bool only_unused_pnts) + bool const only_unused_pnts) { GeoLib::PointVec const* const pnt_obj(getPointVecObj(geo_name)); if (pnt_obj == nullptr) { ERR("Point vector %s not found.", geo_name.c_str()); - return; + return -1; } std::vector<GeoLib::Point*> const& pnts = *pnt_obj->getVector(); if (pnts.empty()) { ERR("Point vector %s is empty.", geo_name.c_str()); - return; + return -1; } std::size_t const n_pnts(pnts.size()); - std::vector<bool> flags(n_pnts, true); + std::vector<bool> transfer_pnts(n_pnts, true); if (only_unused_pnts) - markPointsAsUsed(geo_name, flags); + markUnusedPoints(geo_name, transfer_pnts); - std::unique_ptr<std::vector<GeoLib::Point*>> stations( - new std::vector<GeoLib::Point*>); + auto stations = std::make_unique<std::vector<GeoLib::Point*>>(); for (std::size_t i = 0; i < n_pnts; ++i) { - if (!flags[i]) + if (!transfer_pnts[i]) continue; std::string name = pnt_obj->getItemNameByID(i); if (name.empty()) name = "Station " + std::to_string(i); - stations->push_back(new GeoLib::Station((*pnts[i])[0], (*pnts[i])[1], - (*pnts[i])[2], name)); + stations->push_back(new GeoLib::Station(pnts[i], name)); } std::string vec_name = geo_name + " stations"; if (!stations->empty()) addStationVec(std::move(stations), vec_name); else + { WARN("No points found to convert."); + return 1; + } + return 0; } const GeoLib::GeoObject* GEOObjects::getGeoObject( diff --git a/GeoLib/GEOObjects.h b/GeoLib/GEOObjects.h index 8365b7e5639..b378a914475 100644 --- a/GeoLib/GEOObjects.h +++ b/GeoLib/GEOObjects.h @@ -254,9 +254,9 @@ public: // @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 - void geoPointsToStation(std::string const& geo_name, - std::string const& stn_name, - bool only_unused_pnts = true); + int geoPointsToStation(std::string const& geo_name, + std::string const& 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, @@ -377,7 +377,7 @@ private: void mergeSurfaces(std::vector<std::string> const & geo_names, std::string & merged_geo_name, std::vector<std::size_t> const& pnt_offsets); - void markPointsAsUsed(std::string const& geo_name, - std::vector<bool>& flags); + void markUnusedPoints(std::string const& geo_name, + std::vector<bool>& transfer_pnts) const; }; } // end namespace -- GitLab