Skip to content

Commit

Permalink
Merge pull request #2035 from lpechacek/issue-2012-ocd-undefined-symb…
Browse files Browse the repository at this point in the history
…ol-export

Handle undefined symbols in .ocd export (issues GH-1991 and GH-2012)
  • Loading branch information
lpechacek authored Mar 16, 2022
2 parents 69783a5 + 40b005c commit a419f73
Show file tree
Hide file tree
Showing 3 changed files with 41 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
27 changes: 27 additions & 0 deletions test/data/undefined-objects.omap
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<map xmlns="http://openorienteering.org/apps/mapper/xml/v2" version="9">
<notes></notes>
<georeferencing scale="10000"><projected_crs id="Local"/></georeferencing>
<colors count="0">
</colors>
<barrier version="6" required="0.6.0">
<symbols count="0">
</symbols>
<parts count="1" current="0">
<part name="default part"><objects count="5">
<object type="0" symbol="-2"><coords count="1">4792 1790;</coords></object>
<object type="1" symbol="-3"><coords count="2">3222 1770;-2778 1770;</coords><pattern rotation="0"><coord x="0" y="0"/></pattern></object>
<object type="4" symbol="-4" h_align="1" v_align="0"><coords count="1">1212 0;</coords><text>B</text></object>
<object type="4" symbol="-4" h_align="2" v_align="0"><coords count="1">6137 72;</coords><text>C</text></object>
<object type="4" symbol="-4" h_align="0" v_align="0"><coords count="1">-3667 0;</coords><text>A</text></object>
</objects></part>
</parts>
<templates count="0" first_front_template="0">
<defaults use_meters_per_pixel="true" meters_per_pixel="0" dpi="0" scale="0"/>
</templates>
<view>
<grid color="#80646464" display="0" alignment="0" additional_rotation="0" unit="1" h_spacing="500" v_spacing="500" h_offset="0" v_offset="0" snapping_enabled="true"/>
<map_view zoom="7.44274" position_x="3266" position_y="334"><map opacity="1" visible="true"/><templates count="0"/></map_view>
</view>
</barrier>
</map>
1 change: 1 addition & 0 deletions test/file_format_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ namespace
"data:/examples/forest sample.omap",
"data:/examples/overprinting.omap",
"testdata:templates/world-file.xmap",
"data:undefined-objects.omap",
};

auto const xml_test_files = {
Expand Down

0 comments on commit a419f73

Please sign in to comment.