mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 04:30:05 +00:00 
			
		
		
		
	Add placefile parsing for Icon and IconFile, stub for TimeRange
This commit is contained in:
		
							parent
							
								
									e3449e382d
								
							
						
					
					
						commit
						1f2d5227c4
					
				
					 2 changed files with 95 additions and 4 deletions
				
			
		|  | @ -7,6 +7,7 @@ | |||
| 
 | ||||
| #include <boost/gil/typedefs.hpp> | ||||
| #include <boost/units/quantity.hpp> | ||||
| #include <boost/units/systems/angle/degrees.hpp> | ||||
| #include <boost/units/systems/si/length.hpp> | ||||
| 
 | ||||
| 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<boost::units::si::length> threshold_ {}; | ||||
|    }; | ||||
| 
 | ||||
|    struct IconDrawItem : DrawItem | ||||
|    { | ||||
|       IconDrawItem() { itemType_ = ItemType::Icon; } | ||||
| 
 | ||||
|       double                                                    latitude_ {}; | ||||
|       double                                                    longitude_ {}; | ||||
|       double                                                    x_ {}; | ||||
|       double                                                    y_ {}; | ||||
|       boost::units::quantity<boost::units::degree::plane_angle> angle_ {}; | ||||
|       std::size_t fileNumber_ {0u}; | ||||
|       std::size_t iconNumber_ {0u}; | ||||
|       std::string hoverText_ {}; | ||||
|    }; | ||||
| 
 | ||||
|    struct TextDrawItem : DrawItem | ||||
|    { | ||||
|       TextDrawItem() { itemType_ = ItemType::Text; } | ||||
|  |  | |||
|  | @ -64,7 +64,7 @@ public: | |||
|    DrawingStatement          currentStatement_ {DrawingStatement::Standard}; | ||||
| 
 | ||||
|    // References
 | ||||
|    std::unordered_map<std::size_t, bool>                  iconFiles_ {}; | ||||
|    std::unordered_map<std::size_t, std::shared_ptr<IconFile>> iconFiles_ {}; | ||||
|    std::unordered_map<std::size_t, std::shared_ptr<Font>>     fonts_ {}; | ||||
| 
 | ||||
|    std::vector<std::shared_ptr<DrawItem>> 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<std::string> tokenList = util::ParseTokens( | ||||
|          line, {",", ",", ",", ",", ","}, iconFileKey_.size()); | ||||
| 
 | ||||
|       // TODO
 | ||||
|       if (tokenList.size() >= 6) | ||||
|       { | ||||
|          std::shared_ptr<IconFile> iconFile = std::make_shared<IconFile>(); | ||||
| 
 | ||||
|          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<std::string> tokenList = | ||||
|          util::ParseTokens(line, {",", ",", ",", ",", ","}, iconKey_.size()); | ||||
| 
 | ||||
|       // TODO
 | ||||
|       std::shared_ptr<IconDrawItem> di = nullptr; | ||||
| 
 | ||||
|       if (tokenList.size() >= 5) | ||||
|       { | ||||
|          di = std::make_shared<IconDrawItem>(); | ||||
| 
 | ||||
|          di->threshold_ = threshold_; | ||||
| 
 | ||||
|          ParseLocation(tokenList[0], | ||||
|                        tokenList[1], | ||||
|                        di->latitude_, | ||||
|                        di->longitude_, | ||||
|                        di->x_, | ||||
|                        di->y_); | ||||
| 
 | ||||
|          di->angle_ = static_cast< | ||||
|             boost::units::quantity<boost::units::degree::plane_angle>>( | ||||
|             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_)) | ||||
|    { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat