Add placefile parsing for Line

This commit is contained in:
Dan Paulat 2023-08-06 23:52:26 -05:00
parent f0c2f8eec0
commit 1929ee9eef
2 changed files with 85 additions and 1 deletions

View file

@ -100,6 +100,26 @@ public:
std::string hoverText_ {};
};
struct LineDrawItem : DrawItem
{
LineDrawItem() { itemType_ = ItemType::Line; }
boost::gil::rgba8_pixel_t color_ {};
double width_ {};
std::int32_t flags_ {};
std::string hoverText_ {};
struct Element
{
double latitude_ {};
double longitude_ {};
double x_ {};
double y_ {};
};
std::vector<Element> elements_ {};
};
bool IsValid() const;
/**

View file

@ -46,6 +46,7 @@ public:
double& longitude,
double& x,
double& y);
void ProcessElement(const std::string& line);
void ProcessLine(const std::string& line);
static void ProcessEscapeCharacters(std::string& s);
@ -62,6 +63,7 @@ public:
ColorMode colorMode_ {ColorMode::RGBA};
std::vector<Object> objectStack_ {};
DrawingStatement currentStatement_ {DrawingStatement::Standard};
std::shared_ptr<DrawItem> currentDrawItem_ {nullptr};
// References
std::unordered_map<std::size_t, std::shared_ptr<IconFile>> iconFiles_ {};
@ -179,6 +181,11 @@ std::shared_ptr<Placefile> Placefile::Load(const std::string& name,
if (boost::istarts_with(line, "End:"))
{
placefile->p->currentStatement_ = DrawingStatement::Standard;
placefile->p->currentDrawItem_ = nullptr;
}
else if (placefile->p->currentDrawItem_ != nullptr)
{
placefile->p->ProcessElement(line);
}
break;
}
@ -502,9 +509,39 @@ void Placefile::Impl::ProcessLine(const std::string& line)
// lat, lon
// ...
// End:
std::vector<std::string> tokenList =
util::ParseTokens(line, {",", ","}, lineKey_.size());
currentStatement_ = DrawingStatement::Line;
// TODO
std::shared_ptr<LineDrawItem> di = nullptr;
if (tokenList.size() >= 2)
{
di = std::make_shared<LineDrawItem>();
di->threshold_ = threshold_;
di->color_ = color_;
di->width_ = std::stoul(tokenList[0]);
di->flags_ = std::stoul(tokenList[1]);
}
if (tokenList.size() >= 3)
{
ProcessEscapeCharacters(tokenList[2]);
TrimQuotes(tokenList[2]);
di->hoverText_.swap(tokenList[2]);
}
if (di != nullptr)
{
currentDrawItem_ = di;
drawItems_.emplace_back(std::move(di));
}
else
{
logger_->warn("Line statement malformed: {}", line);
}
}
else if (boost::istarts_with(line, trianglesKey_))
{
@ -548,6 +585,33 @@ void Placefile::Impl::ProcessLine(const std::string& line)
}
}
void Placefile::Impl::ProcessElement(const std::string& line)
{
if (currentStatement_ == DrawingStatement::Line)
{
// Line: width, flags [, hover_text]
// lat, lon
// ...
// End:
std::vector<std::string> tokenList = util::ParseTokens(line, {",", ","});
if (tokenList.size() >= 2)
{
LineDrawItem::Element element;
ParseLocation(tokenList[0],
tokenList[1],
element.latitude_,
element.longitude_,
element.x_,
element.y_);
std::static_pointer_cast<LineDrawItem>(currentDrawItem_)
->elements_.emplace_back(std::move(element));
}
}
}
void Placefile::Impl::ParseLocation(const std::string& latitudeToken,
const std::string& longitudeToken,
double& latitude,