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

Merge branch 'SmallFixes_2021-Week26' into 'master'

[GL] Small code improvements.

See merge request ogs/ogs!3685
parents 204dd947 0dc914cc
No related branches found
No related tags found
No related merge requests found
...@@ -121,9 +121,9 @@ void StationTreeView::contextMenuEvent(QContextMenuEvent* event) ...@@ -121,9 +121,9 @@ void StationTreeView::contextMenuEvent(QContextMenuEvent* event)
QAction* setNameAction = menu.addAction("Set name..."); QAction* setNameAction = menu.addAction("Set name...");
connect(setNameAction, SIGNAL(triggered()), this, connect(setNameAction, SIGNAL(triggered()), this,
SLOT(setNameForElement())); SLOT(setNameForElement()));
if (static_cast<StationTreeModel*>(model()) if (dynamic_cast<GeoLib::StationBorehole*>(
->stationFromIndex(index, temp_name) static_cast<StationTreeModel*>(model())->stationFromIndex(
->type() == GeoLib::Station::StationType::BOREHOLE) index, temp_name)))
{ {
QAction* stratAction = menu.addAction("Display Stratigraphy..."); QAction* stratAction = menu.addAction("Display Stratigraphy...");
QAction* exportAction = menu.addAction("Export to GMS..."); QAction* exportAction = menu.addAction("Export to GMS...");
......
...@@ -95,8 +95,7 @@ int VtkStationSource::RequestData(vtkInformation* request, ...@@ -95,8 +95,7 @@ int VtkStationSource::RequestData(vtkInformation* request,
} }
} }
bool isBorehole = static_cast<GeoLib::Station*>((*_stations)[0])->type() == bool isBorehole = dynamic_cast<GeoLib::StationBorehole*>((*_stations)[0]);
GeoLib::Station::StationType::BOREHOLE;
vtkSmartPointer<vtkInformation> outInfo = vtkSmartPointer<vtkInformation> outInfo =
outputVector->GetInformationObject(0); outputVector->GetInformationObject(0);
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <vtkPolyDataAlgorithm.h> #include <vtkPolyDataAlgorithm.h>
#include "Applications/DataHolderLib/Color.h" #include "Applications/DataHolderLib/Color.h"
#include "GeoLib/StationBorehole.h"
#include "GeoLib/Station.h" #include "GeoLib/Station.h"
#include "VtkAlgorithmProperties.h" #include "VtkAlgorithmProperties.h"
...@@ -36,10 +37,6 @@ public: ...@@ -36,10 +37,6 @@ public:
const std::map<std::string, DataHolderLib::Color>& getColorLookupTable() const const std::map<std::string, DataHolderLib::Color>& getColorLookupTable() const
{ return _colorLookupTable; } { return _colorLookupTable; }
/// Returns the type of observation site represented in this source object
GeoLib::Station::StationType getType() const
{ return static_cast<GeoLib::Station*>((*_stations)[0])->type(); };
/// Sets a predefined color lookup table for the colouring of borehole stratigraphies /// Sets a predefined color lookup table for the colouring of borehole stratigraphies
// int setColorLookupTable(const std::string &filename) // int setColorLookupTable(const std::string &filename)
// { return GeoLib::readColorLookupTable(_colorLookupTable, filename); } // { return GeoLib::readColorLookupTable(_colorLookupTable, filename); }
......
...@@ -1242,17 +1242,16 @@ void MainWindow::showDiagramPrefsDialog(QModelIndex& index) ...@@ -1242,17 +1242,16 @@ void MainWindow::showDiagramPrefsDialog(QModelIndex& index)
GeoLib::Station* stn = GeoLib::Station* stn =
_geo_model->getStationModel()->stationFromIndex(index, listName); _geo_model->getStationModel()->stationFromIndex(index, listName);
if ((stn->type() == GeoLib::Station::StationType::STATION) && if (dynamic_cast<GeoLib::StationBorehole*>(stn))
stn->getSensorData()) {
OGSError::box("No time series data available for borehole.");
}
else if (dynamic_cast<GeoLib::Station*>(stn) && stn->getSensorData())
{ {
auto* prefs(new DiagramPrefsDialog(stn)); auto* prefs(new DiagramPrefsDialog(stn));
prefs->setAttribute(Qt::WA_DeleteOnClose); prefs->setAttribute(Qt::WA_DeleteOnClose);
prefs->show(); prefs->show();
} }
if (stn->type() == GeoLib::Station::StationType::BOREHOLE)
{
OGSError::box("No time series data available for borehole.");
}
} }
void MainWindow::showDiagramPrefsDialog() void MainWindow::showDiagramPrefsDialog()
......
...@@ -264,8 +264,7 @@ bool XmlStnInterface::write() ...@@ -264,8 +264,7 @@ bool XmlStnInterface::write()
const std::vector<GeoLib::Point*>* stations( const std::vector<GeoLib::Point*>* stations(
_geo_objs.getStationVec(export_name)); _geo_objs.getStationVec(export_name));
bool const is_borehole = bool const is_borehole =
static_cast<GeoLib::Station*>((*stations)[0])->type() == dynamic_cast<GeoLib::StationBorehole*>((*stations)[0]);
GeoLib::Station::StationType::BOREHOLE;
doc.appendChild(root); doc.appendChild(root);
QDomElement stationListTag = doc.createElement("stationlist"); QDomElement stationListTag = doc.createElement("stationlist");
......
...@@ -28,18 +28,16 @@ SensorData::SensorData(const std::string& file_name) ...@@ -28,18 +28,16 @@ SensorData::SensorData(const std::string& file_name)
} }
SensorData::SensorData(std::vector<std::size_t> time_steps) SensorData::SensorData(std::vector<std::size_t> time_steps)
: _start(time_steps[0]), : _start(time_steps.front()),
_end(time_steps[time_steps.size() - 1]), _end(time_steps.back()),
_step_size(0), _step_size(0),
_time_unit(TimeStepType::NONE), _time_unit(TimeStepType::NONE),
_time_steps(time_steps) _time_steps(time_steps)
{ {
for (std::size_t i = 1; i < time_steps.size(); i++) if (!std::is_sorted(
time_steps.begin(), time_steps.end(), std::less_equal{}))
{ {
if (time_steps[i - 1] >= time_steps[i]) ERR("Error in SensorData() - Time series has no order!");
{
ERR("Error in SensorData() - Time series has no order!");
}
} }
} }
......
...@@ -22,56 +22,49 @@ ...@@ -22,56 +22,49 @@
namespace GeoLib namespace GeoLib
{ {
Station::Station(double x, double y, double z, std::string name, Station::Station(double x, double y, double z, std::string name)
Station::StationType type) : Point(x, y, z), _name(std::move(name))
: Point(x, y, z), _name(std::move(name)), _type(type)
{ {
} }
Station::Station(Point* coords, std::string name, Station::StationType type) Station::Station(Point* coords, std::string name)
: Point(*coords), _name(std::move(name)), _type(type) : Point(*coords), _name(std::move(name))
{ {
} }
Station::Station(Station const& src) Station::Station(Station const& src)
: Point(src), : Point(src),
_name(src._name), _name(src._name),
_type(src._type), _station_value(src._station_value),
_station_value(src._station_value) _sensor_data(src._sensor_data.get() != nullptr
? new SensorData(*(src._sensor_data.get()))
: nullptr)
{ {
} }
Station::~Station()
{
delete this->_sensor_data;
}
Station* Station::createStation(const std::string& line) Station* Station::createStation(const std::string& line)
{ {
Station* station = new Station();
std::list<std::string> fields = BaseLib::splitString(line, '\t'); std::list<std::string> fields = BaseLib::splitString(line, '\t');
if (fields.size() >= 3) if (fields.size() < 3)
{
auto it = fields.begin();
station->_name = *it;
(*station)[0] = std::strtod(
(BaseLib::replaceString(",", ".", *(++it))).c_str(), nullptr);
(*station)[1] = std::strtod(
(BaseLib::replaceString(",", ".", *(++it))).c_str(), nullptr);
if (++it != fields.end())
{
(*station)[2] = std::strtod(
(BaseLib::replaceString(",", ".", *it)).c_str(), nullptr);
}
}
else
{ {
INFO("Station::createStation() - Unexpected file format."); INFO("Station::createStation() - Unexpected file format.");
delete station;
return nullptr; return nullptr;
} }
return station;
auto it = fields.begin();
std::string name = *it;
auto const x = std::strtod(
(BaseLib::replaceString(",", ".", *(++it))).c_str(), nullptr);
auto const y = std::strtod(
(BaseLib::replaceString(",", ".", *(++it))).c_str(), nullptr);
auto z = 0.0;
if (++it != fields.end())
{
z = std::strtod((BaseLib::replaceString(",", ".", *it)).c_str(),
nullptr);
}
return new Station(x, y, z, name);
} }
Station* Station::createStation(const std::string& name, double x, double y, Station* Station::createStation(const std::string& name, double x, double y,
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#pragma once #pragma once
#include <memory>
#include <string> #include <string>
#include "Point.h" #include "Point.h"
...@@ -35,14 +36,6 @@ namespace GeoLib ...@@ -35,14 +36,6 @@ namespace GeoLib
class Station : public Point class Station : public Point
{ {
public: public:
/// Signals if the object is a "simple" Station or a Borehole (i.e. containing borehole-specific information).
enum class StationType
{
INVALID = 0,
STATION,
BOREHOLE
};
/** /**
* \brief Constructor * \brief Constructor
* *
...@@ -51,15 +44,11 @@ public: ...@@ -51,15 +44,11 @@ public:
* \param y The y-coordinate of the station. * \param y The y-coordinate of the station.
* \param z The z-coordinate of the station. * \param z The z-coordinate of the station.
* \param name The name of the station. * \param name The name of the station.
* \param type The type of the station, see Station::StationType for
* possible values.
*/ */
explicit Station(double x = 0.0, double y = 0.0, double z = 0.0, explicit Station(double x = 0.0, double y = 0.0, double z = 0.0,
std::string name = "", std::string name = "");
Station::StationType type = Station::StationType::STATION);
explicit Station(Point* coords, std::string name = "", explicit Station(Point* coords, std::string name = "");
Station::StationType type = Station::StationType::STATION);
/** /**
* Constructor copies the source object * Constructor copies the source object
...@@ -67,16 +56,11 @@ public: ...@@ -67,16 +56,11 @@ public:
*/ */
Station(Station const& src); Station(Station const& src);
~Station() override;
/// Returns the name of the station. /// Returns the name of the station.
std::string const& getName() const { return _name; } std::string const& getName() const { return _name; }
void setName(std::string const& name) { _name = name; } void setName(std::string const& name) { _name = name; }
/// Returns the GeoSys-station-type for the station.
StationType type() const { return _type; }
/// Creates a Station-object from information contained in a string (assuming the string has the right format) /// Creates a Station-object from information contained in a string (assuming the string has the right format)
static Station* createStation(const std::string &line); static Station* createStation(const std::string &line);
...@@ -90,16 +74,18 @@ public: ...@@ -90,16 +74,18 @@ public:
void setStationValue(double station_value) { this->_station_value = station_value; } void setStationValue(double station_value) { this->_station_value = station_value; }
/// Allows to add sensor data from a CSV file to the observation site /// Allows to add sensor data from a CSV file to the observation site
void addSensorDataFromCSV(const std::string &file_name) { this->_sensor_data = new SensorData(file_name); } void addSensorDataFromCSV(const std::string& file_name)
{
_sensor_data.reset(new SensorData(file_name));
}
/// Returns all the sensor data for this observation site /// Returns all the sensor data for this observation site
const SensorData* getSensorData() const { return this->_sensor_data; } const SensorData* getSensorData() const { return _sensor_data.get(); }
private: private:
std::string _name; std::string _name;
StationType _type{Station::StationType::STATION}; // GeoSys Station Type
double _station_value{0.0}; double _station_value{0.0};
SensorData* _sensor_data{nullptr}; std::unique_ptr<SensorData> _sensor_data{nullptr};
}; };
bool isStation(GeoLib::Point const* pnt); bool isStation(GeoLib::Point const* pnt);
......
...@@ -29,15 +29,10 @@ namespace GeoLib ...@@ -29,15 +29,10 @@ namespace GeoLib
// The Borehole class // // The Borehole class //
//////////////////////// ////////////////////////
StationBorehole::StationBorehole(double x, StationBorehole::StationBorehole(double x, double y, double z,
double y, double const depth, const std::string& name,
double z,
double const depth,
const std::string& name,
int date) int date)
: Station(x, y, z, name, Station::StationType::BOREHOLE), : Station(x, y, z, name), _depth(depth), _date(date)
_depth(depth),
_date(date)
{ {
// add first point of borehole // add first point of borehole
_profilePntVec.push_back(this); _profilePntVec.push_back(this);
......
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