diff --git a/wxdata/include/scwx/gr/placefile.hpp b/wxdata/include/scwx/gr/placefile.hpp index 4a4f624b..d2a70c76 100644 --- a/wxdata/include/scwx/gr/placefile.hpp +++ b/wxdata/include/scwx/gr/placefile.hpp @@ -7,6 +7,7 @@ #include #include +#include #include namespace scwx @@ -47,6 +48,16 @@ public: Unknown }; + struct IconFile + { + std::size_t fileNumber_ {}; + std::size_t iconWidth_ {}; + std::size_t iconHeight_ {}; + std::size_t hotX_ {}; + std::size_t hotY_ {}; + std::string filename_ {}; + }; + struct Font { std::size_t fontNumber_ {}; @@ -61,6 +72,20 @@ public: boost::units::quantity threshold_ {}; }; + struct IconDrawItem : DrawItem + { + IconDrawItem() { itemType_ = ItemType::Icon; } + + double latitude_ {}; + double longitude_ {}; + double x_ {}; + double y_ {}; + boost::units::quantity angle_ {}; + std::size_t fileNumber_ {0u}; + std::size_t iconNumber_ {0u}; + std::string hoverText_ {}; + }; + struct TextDrawItem : DrawItem { TextDrawItem() { itemType_ = ItemType::Text; } diff --git a/wxdata/source/scwx/gr/placefile.cpp b/wxdata/source/scwx/gr/placefile.cpp index a2e62dcf..10b9bedd 100644 --- a/wxdata/source/scwx/gr/placefile.cpp +++ b/wxdata/source/scwx/gr/placefile.cpp @@ -64,8 +64,8 @@ public: DrawingStatement currentStatement_ {DrawingStatement::Standard}; // References - std::unordered_map iconFiles_ {}; - std::unordered_map> fonts_ {}; + std::unordered_map> iconFiles_ {}; + std::unordered_map> fonts_ {}; std::vector> drawItems_ {}; }; @@ -184,6 +184,7 @@ void Placefile::Impl::ProcessLine(const std::string& line) { static const std::string titleKey_ {"Title:"}; static const std::string thresholdKey_ {"Threshold:"}; + static const std::string timeRangeKey_ {"TimeRange:"}; static const std::string hsluvKey_ {"HSLuv:"}; static const std::string colorKey_ {"Color:"}; static const std::string refreshKey_ {"Refresh:"}; @@ -225,6 +226,12 @@ void Placefile::Impl::ProcessLine(const std::string& line) boost::units::metric::nautical_mile_base_unit::unit_type()); } } + else if (boost::istarts_with(line, timeRangeKey_)) + { + // TimeRange: start_time end_time + + // TODO + } else if (boost::istarts_with(line, hsluvKey_)) { // HSLuv: value @@ -309,14 +316,73 @@ void Placefile::Impl::ProcessLine(const std::string& line) else if (boost::istarts_with(line, iconFileKey_)) { // IconFile: fileNumber, iconWidth, iconHeight, hotX, hotY, fileName + std::vector tokenList = util::ParseTokens( + line, {",", ",", ",", ",", ","}, iconFileKey_.size()); - // TODO + if (tokenList.size() >= 6) + { + std::shared_ptr iconFile = std::make_shared(); + + iconFile->fileNumber_ = std::stoul(tokenList[0]); + iconFile->iconWidth_ = std::stoul(tokenList[1]); + iconFile->iconHeight_ = std::stoul(tokenList[2]); + iconFile->hotX_ = std::stoul(tokenList[3]); + iconFile->hotY_ = std::stoul(tokenList[4]); + + TrimQuotes(tokenList[5]); + iconFile->filename_.swap(tokenList[5]); + + iconFiles_.insert_or_assign(iconFile->fileNumber_, iconFile); + } + else + { + logger_->warn("IconFile statement malformed: {}", line); + } } else if (boost::istarts_with(line, iconKey_)) { // Icon: lat, lon, angle, fileNumber, iconNumber, hoverText + std::vector tokenList = + util::ParseTokens(line, {",", ",", ",", ",", ","}, iconKey_.size()); - // TODO + std::shared_ptr di = nullptr; + + if (tokenList.size() >= 5) + { + di = std::make_shared(); + + di->threshold_ = threshold_; + + ParseLocation(tokenList[0], + tokenList[1], + di->latitude_, + di->longitude_, + di->x_, + di->y_); + + di->angle_ = static_cast< + boost::units::quantity>( + std::stod(tokenList[2]) * + boost::units::angle::degree_base_unit::unit_type()); + + di->fileNumber_ = std::stoul(tokenList[3]); + di->iconNumber_ = std::stoul(tokenList[4]); + } + if (tokenList.size() >= 6) + { + ProcessEscapeCharacters(tokenList[5]); + TrimQuotes(tokenList[5]); + di->hoverText_.swap(tokenList[5]); + } + + if (di != nullptr) + { + drawItems_.emplace_back(std::move(di)); + } + else + { + logger_->warn("Icon statement malformed: {}", line); + } } else if (boost::istarts_with(line, fontKey_)) {