Skip to content

Commit

Permalink
OcdFileImport: Handle graphic objects
Browse files Browse the repository at this point in the history
OCD format recognizes symbol-less map objects that, however, render in
map colors. They are called "graphic objects". We create synthetic
symbols for graphic objects on import. All the Mapper symbols have the
same name and number reflecting the anonymous nature of the source
graphic objects.

Closes OpenOrienteeringGH-959.
  • Loading branch information
lpechacek committed Aug 11, 2021
1 parent e8a3925 commit 88e9934
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 2 deletions.
83 changes: 81 additions & 2 deletions src/fileformats/ocd_file_import.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1884,13 +1884,92 @@ void OcdFileImport::setupPointSymbolPattern(PointSymbol* symbol, std::size_t dat
}
}


Symbol* OcdFileImport::getGraphicObjectSymbol(const Ocd::ObjectV8& ocd_object)
{
Q_UNUSED(ocd_object);
return nullptr;
}


template< class O >
Symbol* OcdFileImport::getGraphicObjectSymbol(const O& ocd_object)
{
Symbol* symbol = nullptr;
auto symbol_setup_common = [](Symbol& symbol) {
symbol.setName(QLatin1String("helper symbol for graphic objects"));
symbol.setNumberComponent(0, 999);
symbol.setNumberComponent(1, -1);
symbol.setNumberComponent(2, -1);
};

auto get_cached_symbol = [this](const quint64 key) {
return graphic_symbol_index.contains(key) ?
graphic_symbol_index[key] : nullptr;
};

auto store_cached_symbol = [this](const quint64 key, Symbol* symbol) {
map->addSymbol(symbol, map->getNumSymbols());
graphic_symbol_index[key] = symbol;
};

switch (ocd_object.type)
{
case Ocd::ObjectTypeLine:
{
const auto g_key = quint64(ocd_object.color)
| quint64(ocd_object.line_width) << 32
| quint64(Ocd::ObjectTypeLine) << 56;
symbol = get_cached_symbol(g_key);
if (!symbol)
{
auto* line_symbol = new OcdImportedLineSymbol();
symbol_setup_common(*line_symbol);
line_symbol->color = convertColor(ocd_object.color);
line_symbol->line_width = convertLength(ocd_object.line_width);
symbol = line_symbol;
store_cached_symbol(g_key, symbol);
}
}
break;
case Ocd::ObjectTypeArea:
{
const auto g_key = quint64(ocd_object.color)
| quint64(Ocd::ObjectTypeArea) << 56;
symbol = get_cached_symbol(g_key);
if (!symbol)
{
auto* area_symbol = new OcdImportedAreaSymbol();
symbol_setup_common(*area_symbol);
area_symbol->color = convertColor(ocd_object.color);
symbol = area_symbol;
store_cached_symbol(g_key, symbol);
}
}
break;
default:
addWarning(tr("Encountered an unsupported type of graphic object (%1). Skipping.").arg(ocd_object.type));
break;
}

return symbol;
}


template< class O >
Object* OcdFileImport::importObject(const O& ocd_object, MapPart* part)
{
Symbol* symbol = nullptr;
if (ocd_object.symbol >= 0)
switch (ocd_object.symbol)
{
symbol = symbol_index[ocd_object.symbol];
case -2: // graphic object
symbol = getGraphicObjectSymbol(ocd_object);
break;
default:
if (ocd_object.symbol >= 0)
{
symbol = symbol_index[ocd_object.symbol];
}
}

if (!symbol)
Expand Down
8 changes: 8 additions & 0 deletions src/fileformats/ocd_file_import.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,11 @@ class OcdFileImport : public Importer
template< class O >
Object* importObject(const O& ocd_object, MapPart* part);

Symbol* getGraphicObjectSymbol(const Ocd::ObjectV8& ocd_object);

template< class O >
Symbol* getGraphicObjectSymbol(const O& ocd_object);

QString getObjectText(const Ocd::ObjectV8& ocd_object) const;

template< class O >
Expand Down Expand Up @@ -350,6 +355,9 @@ class OcdFileImport : public Importer
/// maps OCD symbol number to oo-mapper symbol object
QHash<unsigned int, Symbol *> symbol_index;

/// maps OCD graphic object properties to oo-mapper synthetic symbol object
QHash<quint64, Symbol *> graphic_symbol_index;

/// maps OO Mapper text symbol pointer to OCD defined horizontal alignment (stored in objects instead of symbols in OO Mapper)
QHash<Symbol*, TextObject::HorizontalAlignment> text_halign_map;

Expand Down
14 changes: 14 additions & 0 deletions src/fileformats/ocd_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,20 @@ namespace Ocd
SymbolHidden = 2
};

/**
* Object type values.
*/
enum ObjectType
{
ObjectTypePoint = 1,
ObjectTypeLine = 2,
ObjectTypeArea = 3,
ObjectTypeUnformattedText = 4,
ObjectTypeFormattedText = 5,
ObjectTypeLineText = 6,
ObjectTypeRectangle = 7,
};

/**
* Status values for objects.
*/
Expand Down

0 comments on commit 88e9934

Please # to comment.