Skip to content

Commit

Permalink
OcdFileExport: Export objects with undefined symbols
Browse files Browse the repository at this point in the history
This commit fixes multiple issues with .ocd export. Line and point
objects were exported with symbol number 0 while the typical value for
such objects is -1. Text object export routines didn't recognize the
undefined text symbol and choke on it, failing to export previously
imported objects.

Closes GH-2012.
  • Loading branch information
lpechacek committed Dec 28, 2021
1 parent e247f72 commit e1b6f4a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/fileformats/ocd_file_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2507,7 +2507,9 @@ QByteArray OcdFileExport::exportPointObject(const PointObject* point, typename O
{
OcdObject ocd_object = {};
ocd_object.type = 1;
ocd_object.symbol = entry.symbol = decltype(entry.symbol)(symbol_numbers[point->getSymbol()]);
auto const symbol_number_it = symbol_numbers.find(point->getSymbol());
decltype(entry.symbol) const symbol_number = symbol_number_it != symbol_numbers.end() ? symbol_number_it->second : -1;
ocd_object.symbol = entry.symbol = symbol_number;
ocd_object.angle = decltype(ocd_object.angle)(convertRotation(point->getRotation()));
return exportObjectCommon(point, ocd_object, entry);
}
Expand Down Expand Up @@ -2543,7 +2545,9 @@ void OcdFileExport::exportPathObject(OcdFile<Format>& file, const PathObject* pa

if (!need_split_lines)
{
ocd_object.symbol = entry.symbol = decltype(entry.symbol)(symbol_numbers[symbol]);
auto const symbol_number_it = symbol_numbers.find(symbol);
decltype(entry.symbol) const symbol_number = symbol_number_it != symbol_numbers.end() ? symbol_number_it->second : -1;
ocd_object.symbol = entry.symbol = symbol_number;
auto data = exportObjectCommon(path, ocd_object, entry);
FILEFORMAT_ASSERT(!data.isEmpty());

Expand Down Expand Up @@ -2619,11 +2623,16 @@ QByteArray OcdFileExport::exportTextObject(const TextObject* text, typename OcdO
auto text_format = std::find_if(begin(text_format_mapping), end(text_format_mapping), [symbol, alignment](const auto& m) {
return m.symbol == symbol && m.alignment == alignment;
});
FILEFORMAT_ASSERT(text_format != end(text_format_mapping));

decltype(entry.symbol) symbol_number = -1;
if (text_format != end(text_format_mapping))
symbol_number = text_format->symbol_number;
else
FILEFORMAT_ASSERT(map->findSymbolIndex(symbol) < -1); // -2 and below indicate objects with undefined symbols

OcdObject ocd_object = {};
ocd_object.type = text->hasSingleAnchor() ? 4 : 5;
ocd_object.symbol = entry.symbol = decltype(entry.symbol)(text_format->symbol_number);
ocd_object.symbol = entry.symbol = symbol_number;
ocd_object.angle = decltype(ocd_object.angle)(convertRotation(text->getRotation()));
return exportObjectCommon(text, ocd_object, entry);
}
Expand Down

0 comments on commit e1b6f4a

Please sign in to comment.