Skip to content

Commit ec41f6d

Browse files
committed
OcdFileExport: Update per-symbol color list
Per-symbol color information was implemented for the color bitmask in OCD version 8, but not for the color counter and index list in newer versions of the format. Assumed to resolve GH-1452 (map not displayed in CONDES).
1 parent 9cda761 commit ec41f6d

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

src/fileformats/ocd_file_export.cpp

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,14 @@ void OcdFileExport::setupBaseSymbol(const Symbol* symbol, quint32 symbol_number,
10401040
if (symbol->isHidden())
10411041
ocd_base_symbol.status |= Ocd::SymbolHidden;
10421042

1043-
// Set of used colors
1043+
setupSymbolColors(symbol, ocd_base_symbol);
1044+
setupIcon(symbol, ocd_base_symbol);
1045+
}
1046+
1047+
1048+
template< >
1049+
void OcdFileExport::setupSymbolColors<Ocd::BaseSymbolV8>(const Symbol* symbol, Ocd::BaseSymbolV8& ocd_base_symbol)
1050+
{
10441051
using ColorBitmask = typename std::remove_extent<typename std::remove_pointer<decltype(ocd_base_symbol.colors)>::type>::type;
10451052
Q_STATIC_ASSERT(std::is_unsigned<ColorBitmask>::value);
10461053
ColorBitmask bitmask = 1;
@@ -1066,8 +1073,43 @@ void OcdFileExport::setupBaseSymbol(const Symbol* symbol, quint32 symbol_number,
10661073
break;
10671074
}
10681075
}
1076+
}
1077+
1078+
template< class OcdBaseSymbol >
1079+
void OcdFileExport::setupSymbolColors(const Symbol* symbol, OcdBaseSymbol& ocd_base_symbol)
1080+
{
1081+
using std::begin; using std::end;
1082+
setupSymbolColors(symbol, ocd_base_symbol.num_colors, begin(ocd_base_symbol.colors), end(ocd_base_symbol.colors));
1083+
}
1084+
1085+
template< typename Counter, typename Iterator >
1086+
void OcdFileExport::setupSymbolColors(const Symbol* symbol, Counter& num_colors, Iterator first, Iterator last)
1087+
{
1088+
using IndexType = typename std::remove_reference<decltype(*first)>::type;
1089+
Q_STATIC_ASSERT(std::is_signed<Counter>::value);
10691090

1070-
setupIcon(symbol, ocd_base_symbol);
1091+
num_colors = 0;
1092+
auto registration = 0;
1093+
if (uses_registration_color && symbol->containsColor(map->getRegistrationColor()))
1094+
{
1095+
registration = 1;
1096+
}
1097+
1098+
auto it = first;
1099+
for (int c = 0; c < map->getNumColors(); ++c)
1100+
{
1101+
if (!symbol->containsColor(map->getColor(c)))
1102+
continue;
1103+
1104+
++num_colors;
1105+
*it = IndexType(c + registration);
1106+
1107+
if (++it == last)
1108+
{
1109+
num_colors = Counter(-1);
1110+
break;
1111+
}
1112+
}
10711113
}
10721114

10731115

@@ -2057,6 +2099,7 @@ QByteArray OcdFileExport::exportCombinedAreaSymbol(
20572099
{
20582100
auto ocd_symbol = exportAreaSymbol<OcdAreaSymbol>(area_symbol, symbol_number);
20592101
auto ocd_subsymbol_data = reinterpret_cast<OcdAreaSymbol*>(ocd_symbol.data());
2102+
setupSymbolColors(combined_symbol, ocd_subsymbol_data->base);
20602103
setupIcon(combined_symbol, ocd_subsymbol_data->base);
20612104
ocd_subsymbol_data->common.border_on_V9 = 1;
20622105
ocd_subsymbol_data->border_symbol = symbol_numbers[line_symbol];
@@ -2074,6 +2117,7 @@ QByteArray OcdFileExport::exportCombinedLineSymbol(
20742117
{
20752118
auto ocd_symbol = exportLineSymbol<OcdLineSymbol>(main_line, symbol_number);
20762119
auto ocd_symbol_data = reinterpret_cast<OcdLineSymbol*>(ocd_symbol.data());
2120+
setupSymbolColors(combined_symbol, ocd_symbol_data->base);
20772121
setupIcon(combined_symbol, ocd_symbol_data->base);
20782122

20792123
auto& ocd_line_common = ocd_symbol_data->common;

src/fileformats/ocd_file_export.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ class OcdFileExport : public Exporter
169169
template< class OcdBaseSymbol >
170170
void setupBaseSymbol(const Symbol* symbol, quint32 symbol_number, OcdBaseSymbol& ocd_base_symbol);
171171

172+
template< class OcdBaseSymbol >
173+
void setupSymbolColors(const Symbol* symbol, OcdBaseSymbol& ocd_base_symbol);
174+
175+
template< typename Counter, typename Iterator >
176+
void setupSymbolColors(const Symbol* symbol, Counter& num_colors, Iterator first, Iterator last);
177+
172178
template< class OcdBaseSymbol >
173179
void setupIcon(const Symbol* symbol, OcdBaseSymbol& ocd_base_symbol);
174180

src/fileformats/ocd_types_v11.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace Ocd
4646
qint32 extent;
4747
quint32 file_pos;
4848
quint8 RESERVED_MEMBER[2];
49-
quint16 num_colors;
49+
qint16 num_colors;
5050
quint16 colors[14];
5151
Utf16PascalString<64> description;
5252
IconV9 icon;

src/fileformats/ocd_types_v9.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ namespace Ocd
205205
qint32 extent;
206206
qint32 file_pos;
207207
quint16 group;
208-
quint16 num_colors;
208+
qint16 num_colors;
209209
quint16 colors[14];
210210
PascalString<31> description;
211211
IconV9 icon;

0 commit comments

Comments
 (0)