Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 44 additions & 34 deletions area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ vsid::Area::Area(std::vector<std::pair<std::string, std::string>> &coords, bool
{
for (std::pair<std::string, std::string>& coord : coords)
{
if(coord.first.empty() || coord.second.empty())
{
messageHandler->writeMessage("WARNING", "Empty coordinate string found (first: \"" + coord.first +
"\" / second: \"" + coord.second + "\"! Skipping coordinate.");
continue;
}
this->points.push_back(toPoint(coord));
}

Expand All @@ -37,49 +43,53 @@ void vsid::Area::showline()
{
for (auto& line : this->lines)
{
messageHandler->writeMessage("DEBUG", "line: " + std::to_string(line.first.lon) + ":" + std::to_string(line.first.lat) + " - " + std::to_string(line.second.lon) + "." + std::to_string(line.second.lat));
messageHandler->writeMessage("DEBUG", "line: " + std::to_string(line.first.lon) + ":" + std::to_string(line.first.lat) + " - " +
std::to_string(line.second.lon) + "." + std::to_string(line.second.lat));
}
}

vsid::Area::Point vsid::Area::toPoint(std::pair<std::string, std::string> &pos)
{
double lat = toDeg(pos.first);
double lon = toDeg(pos.second);
/*double lat = toDeg(pos.first);
double lon = toDeg(pos.second);*/

double lat = vsid::utils::toDeg(pos.first);
double lon = vsid::utils::toDeg(pos.second);

return {lat, lon};
}

double vsid::Area::toDeg(std::string& coord)
{
std::vector<std::string> dms = vsid::utils::split(coord, '.');
int multi = 0; // default state in exception case

try
{
if (dms.size() < 4)
throw std::out_of_range("Coordinate string \"" + coord + "\" does not contain enough parts for DMS conversion!");

multi = (dms.at(0).find('S') != std::string::npos || dms.at(0).find('W') != std::string::npos) ? -1 : 1;

double deg = std::stod(dms[0].substr(1, dms[0].length()));
double min = std::stod(dms[1]) / 60;
double sec = (std::stod(dms[2]) + std::stod("0." + dms[3])) / 3600;

return (deg + min + sec) * multi;
}
catch (std::out_of_range &e)
{
messageHandler->writeMessage("ERROR", "Out of bounds while calculating coordinate: " + coord + ". " + e.what());
}
catch (const std::invalid_argument& e)
{
messageHandler->writeMessage("ERROR", "Invalid number format in coord " + coord + ". " + e.what());
}

messageHandler->writeMessage("WARNING", "Fallback state for \"" + coord + "\"! Failed to calculate. DMS will be set to 0.0");

return 0.0;
}
//double vsid::Area::toDeg(std::string& coord)
//{
// std::vector<std::string> dms = vsid::utils::split(coord, '.');
// int multi = 0; // default state in exception case
//
// try
// {
// if (dms.size() < 4)
// throw std::out_of_range("Coordinate string \"" + coord + "\" does not contain enough parts for DMS conversion!");
//
// multi = (dms.at(0).find('S') != std::string::npos || dms.at(0).find('W') != std::string::npos) ? -1 : 1;
//
// double deg = std::stod(dms[0].substr(1, dms[0].length()));
// double min = std::stod(dms[1]) / 60;
// double sec = (std::stod(dms[2]) + std::stod("0." + dms[3])) / 3600;
//
// return (deg + min + sec) * multi;
// }
// catch (std::out_of_range &e)
// {
// messageHandler->writeMessage("ERROR", "Out of bounds while calculating coordinate: " + coord + ". " + e.what());
// }
// catch (const std::invalid_argument& e)
// {
// messageHandler->writeMessage("ERROR", "Invalid number format in coord " + coord + ". " + e.what());
// }
//
// messageHandler->writeMessage("WARNING", "Fallback state for \"" + coord + "\"! Failed to calculate. DMS will be set to 0.0");
//
// return 0.0;
//}

bool vsid::Area::inside(const EuroScopePlugIn::CPosition& fplnPos)
{
Expand Down
2 changes: 1 addition & 1 deletion area.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ namespace vsid
* @param coord
* @return double
*/
double toDeg(std::string& coord);
/*double toDeg(std::string& coord);*/
};
}
12 changes: 12 additions & 0 deletions eseparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ void vsid::EseParser::line(Section s, std::string_view l)
if (((visLat.front() == 'N' || visLat.front() == 'S') && std::isdigit(static_cast<unsigned char>(visLat.back()))) &&
((visLon.front() == 'E' || visLon.front() == 'W') && std::isdigit(static_cast<unsigned char>(visLon.back()))))
{
if (visLat.empty() || visLon.empty())
{
messageHandler->writeMessage("WARNING", "Empty coordinate string found for ATC station \"" + atcVec.at(0) +
"\" vis point (lat: \"" + visLat + "\" / lon: \"" + visLon + "\"! Skipping coordinate.");

messageHandler->writeMessage("DEBUG", "[ESE] empty vispoint lat (\"" + visLat + "\" / lon (\"" + visLon +
"\" in line : " + std::string(l), vsid::MessageHandler::DebugArea::Conf);

++idx;
continue;
}

visPoints.push_back(vsid::utils::toPoint({ visLat, visLon }));
}

Expand Down
33 changes: 23 additions & 10 deletions utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,25 +144,38 @@ EuroScopePlugIn::CPosition vsid::utils::toPoint(const std::pair<std::string, std

double vsid::utils::toDeg(const std::string& coord)
{
if (coord.empty())
{
messageHandler->writeMessage("WARNING", "Empty coordinate string found! Skipping coordinate.");
return 0.0;
}

std::vector<std::string> dms = vsid::utils::split(coord, '.');
int multi = 0; // default state in exception case

try
{
if (dms.size() < 4)
throw std::out_of_range("Coordinate string \"" + coord + "\" does not contain enough parts for DMS conversion!");

multi = (dms.at(0).find('S') != std::string::npos || dms.at(0).find('W') != std::string::npos) ? -1 : 1;

double deg = std::stod(dms[0].substr(1, dms[0].length()));
double min = std::stod(dms[1]) / 60;
double sec = (std::stod(dms[2]) + std::stod("0." + dms[3])) / 3600;

return (deg + min + sec) * multi;
}
catch (std::out_of_range)
catch (std::out_of_range& e)
{
messageHandler->writeMessage("ERROR", "Failed to get multiplier while calculating coordinate: " + coord);
messageHandler->writeMessage("ERROR", "Out of bounds while calculating coordinate: " + coord + ". " + e.what());
}

double deg = std::stod(dms[0].substr(1, dms[0].length()));
double min = std::stod(dms[1]) / 60;
double sec = (std::stod(dms[2]) + std::stod("0." + dms[3])) / 3600;

if (multi == 0)
catch (const std::invalid_argument& e)
{
messageHandler->writeMessage("WARNING", "Coordinate \"" + coord + "\" will be multiplied with 0 which will render false results!");
messageHandler->writeMessage("ERROR", "Invalid number format in coord " + coord + ". " + e.what());
}
return (deg + min + sec) * multi;

messageHandler->writeMessage("WARNING", "Fallback state for \"" + coord + "\"! Failed to calculate. DMS will be set to 0.0");

return 0.0;
}
Loading