Files
qt5-legatus-legacy/Lts/Viewer/SituationMap/SymbologyXML/symbol_table.h
T
2026-08-13 18:33:10 +02:00

392 lines
11 KiB
C++
Executable File

/**
* @RDE_HEADER@
* $Id$
* $HeadURL$
* $Author$
*/
#pragma once
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QMap>
#include <QtCore/QSet>
#include <NGLLogger/INGLLogger.h>
#include "symbology_xml_export.h"
#include "symbol.h"
#include "symbol_types.h"
namespace SymbologyXML
{
/*
Frame: Dimension-1 << 16 + Affiliation-1 << 8
BCDAB: 1 << 24
Mobility: 2 << 24
Branch: 3 << 24
CommandLevel: 4 << 24
Vehicle: 5 << 24
IntrinsicMobility: 6 << 24
Arming: 7 << 24
Misc: 8 << 24
Sector1: 9 << 24
Sector2: 10 << 24
*/
/**
@author Stephan Kuhagen <stephan.kuhagen@rheinmetall.com>
*/
class SYMBOLOGY_XML_EXPORT SymbolTable
{
public:
SymbolTable(const SymbolTable &) = delete;
SymbolTable &operator=(const SymbolTable &) = delete;
explicit SymbolTable(const char *loggerName = "AdvSymbologyXML.SymbolTable");
~SymbolTable();
/**
Set the current directory where the symbols should read from. The former
symbols in the cache will be destroyed and the QMap is initialized from
the directory given.
\param directory directory to read symbols from
\param nameFilter: A list of name filters as used in shell-environments.
Examples: '*.xml', 'file_??.xml', where '??' mean two
chars of any kind.
\return true on success, false otherwise (e.g. directory does not exist)
*/
bool setDirectory(const QString &directory, const QStringList & nameFilters = QStringList());
/**
Update the Symbol with ID. If there is currently no symbol with ID, it is
created by this method.
\param id: Update this Symbol from the same source as given in initFrom*
\return true on success, false on error
*/
bool updateSymbol(int id, bool replace = false);
/**
Overload from QMap<>
If there are multiple items for key in the map, the map is searched for the
value as follows: Either return the first Symbol, which has _affil and _dimen
set to undefined and transformed() == false, or if this does not exist, the
first available, which matches key
*/
Symbol* value(const int key, Symbol *defaultValue = nullptr) const;
QList<Symbol*> values(int key) const;
/**
* Overload from QMap<>
If there are multiple items for key in the map, the map is searched for the
value as follows: Either return the first Symbol, which has _affil and _dimen
set to undefined and transformed() == false, or if this does not exist, the
first available, which matches key
*/
Symbol* operator[](const int &key);
/**
Overload from QMap<>
If there are multiple items for key in the map, the map is searched for the
value as follows: Either return the first Symbol, which has _affil and _dimen
set to undefined and transformed() == false, or if this does not exist, the
first available, which matches key
*/
const Symbol* operator[](const int &key) const;
/**
Create a Frame-Symbol-ID for a given Symbol. The Function returns a
Symbol-ID by combining the attributes Affiliation, Dimension and the
fill-flag.
\param symbol: The Symbol
\return The ID created by combining the attributes
*/
static int getFrameSymbolID(const Symbol& symbol) {
//
SymbolTypes::t_affil affil = symbol.getAffil();
if(affil == SymbolTypes::PENDING) {
affil = SymbolTypes::UNKNOWN;
}
if(affil == SymbolTypes::SUSPECT) {
affil = SymbolTypes::ENEMY;
}
if(affil == SymbolTypes::ASSUMED_FRIEND) {
affil = SymbolTypes::FRIEND;
}
return getFrameSymbolID(symbol.getDimen(), affil);
}
/**
Create a Frame-Symbol-ID. The Function returns a Symbol-ID by combining
the attributes Affiliation, Dimension and the fill-flag.
\param dimen: The Symbols Dimension (enum t_dimen in symbol.h)
\param affil: The Symbols Affiliation (enum t_affil in symbol.h)
\return The ID created by combining the attributes
*/
static int getFrameSymbolID(SymbolTypes::t_dimen dimen, SymbolTypes::t_affil affil) {
return ( (dimen-1) <<16 ) +
( (affil-1) << 8 ); // + int(outline);
}
/**
Create a Mobility-Symbol-ID for a given Symbol.
\param symbol: The Symbol
\return The ID created by combining the attributes
*/
static int getMobilitySymbolID(const Symbol& symbol) {
return ( 2<<24 ) + symbol.getMob();
}
/**
Create a Mobility-Symbol-ID for a given Symbol.
\param mob: The Symbols Mobility (enum t_mob in symbol.h)
\return The ID created by combining the attributes
*/
static int getMobilitySymbolID(SymbolTypes::t_mob mob) {
return ( 2<<24 ) + mob;
}
/**
Create a BCDAB-Symbol-ID for a given Symbol.
\param symbol: The Symbol
\return The ID created by combining the attributes
*/
static int getBCDABSymbolID(const Symbol& symbol) {
return ( 1<<24 ) + symbol.getBcdab();
}
/**
Create a BCDAB-Symbol-ID for a given Symbol.
\param v: The Symbols BCDAB-Value (enum t_bcdab in symbol.h)
\return The ID created by combining the attributes
*/
static int getBCDABSymbolID(SymbolTypes::t_bcdab v) {
return ( 1<<24 ) + v;
}
/**
Create a CommandLevel-Symbol-ID for a given Symbol.
\param symbol: The Symbol
\return The ID created by combining the attributes
*/
static int getCommandLevelSymbolID(const Symbol& symbol) {
return ( 4<<24 ) + symbol.getCommandLevel();
}
/**
Create a CommandLevel-Symbol-ID for a given Symbol.
\param v: The Symbols CommandLevel-Value (enum t_commandLevel in symbol.h)
\return The ID created by combining the attributes
*/
static int getCommandLevelSymbolID(SymbolTypes::t_commandlevel v) {
return ( 4<<24 ) + v;
}
/**
Create a Branch-Symbol-ID for a given Symbol. (Truppengattung)
\param v: The Symbols Truppengattung-Value (enum t_branch in symbol.h)
\return The ID created by combining the attributes
*/
static int getBranchSymbolID(SymbolTypes::t_branch v) {
return ( 3<<24 ) + v;
}
/**
Create a Vehicle-Symbol-ID for a given Symbol.
\param symbol: The Symbol
\return The ID created by combining the attributes
*/
static int getVehicleSymbolID(const Symbol& symbol) {
return ( 5<<24 ) + symbol.getVehicle();
}
/**
Create a Vehicle-Symbol-ID for a given Symbol.
\param v: The Symbols Vehicle-Value (enum t_Vehicle in symbol.h)
\return The ID created by combining the attributes
*/
static int getVehicleSymbolID(SymbolTypes::t_vehicle v) {
return ( 5<<24 ) + v;
}
/**
Create a IntrinsicMobility-Symbol-ID for a given Symbol.
\param symbol: The Symbol
\return The ID created by combining the attributes
*/
static int getIntrinsicMobilitySymbolID(const Symbol& symbol) {
return ( 6<<24 ) + symbol.getIntrinsicMob();
}
/**
Create a IntrinsicMobility-Symbol-ID for a given Symbol.
\param v: The Symbols IntrinsicMobility-Value (enum t_intrinsicmob in symbol_types.h)
\return The ID created by combining the attributes
*/
static int getIntrinsicMobilitySymbolID(SymbolTypes::t_intrinsicmob v) {
return ( 6<<24 ) + v;
}
/**
Create a Arming-Symbol-ID for a given Symbol.
\param symbol: The Symbol
\return The ID created by combining the attributes
*/
static int getArmingSymbolID(const Symbol& symbol) {
return ( 7<<24 ) + symbol.getArming();
}
/**
Create a Arming-Symbol-ID for a given Symbol.
\param v: The Symbols arming-Value (enum t_arming in symbol_types.h)
\return The ID created by combining the attributes
*/
static int getArmingSymbolID(SymbolTypes::t_arming v) {
return ( 7<<24 ) + v;
}
/**
Create a Misc-Symbol-ID for a given Symbol
\param v: The Symbols Misc-Value (enum t_misc in symbol_types.h)
\return The ID created by combining the attributes
*/
static int getMiscSymbolID(SymbolTypes::t_misc v) {
return ( 8<<24 ) + v;
}
/**
Create a Sector1-Symbol-ID for a given Symbol
\param v: The Symbols Sector1-Value (enum t_sector1 in symbol_types.h)
\return The ID created by combining the attributes
*/
static int getSector1SymbolID(const Symbol& symbol) {
return ( 9<<24 ) + symbol.getSector1();
}
/**
Create a Sector1-Symbol-ID for a given Symbol
\param v: The Symbols Sector1-Value (enum t_sector1 in symbol_types.h)
\return The ID created by combining the attributes
*/
static int getSector1SymbolID(SymbolTypes::t_sector1 v) {
return ( 9<<24 ) + v;
}
/**
Create a SectorIcon-Symbol-ID for a given Symbol
\param v: The Symbols SectorIcon-Value (enum t_sectoricon in symbol_types.h)
\return The ID created by combining the attributes
*/
static int getSectorIconSymbolID(const Symbol& symbol) {
return ( 10<<24 ) + symbol.getSectorIcon();
}
/**
Create a SectorIcon-Symbol-ID for a given Symbol
\param v: The Symbols SectorIcon-Value (enum t_sectoricon in symbol_types.h)
\return The ID created by combining the attributes
*/
static int getSectorIconSymbolID(SymbolTypes::t_sectoricon v) {
return ( 10<<24 ) + v;
}
/**
Create an AddOn SymbolId_Cont_T for the given Symbols
\param vbg: The vbg_struct
\return The SymbolId_Cont_T created by combining the attributes
*/
typedef int SymbolId_T;
typedef QSet<SymbolId_T> SymbolId_Cont_T;
static SymbolTable::SymbolId_Cont_T getVbgSymbolIDs(const SymbolTypes::vbg_struct &vbg)
{
SymbolId_Cont_T ret;
const SymbolTypes::vbg_et &v = vbg.vbg;
constexpr int idBase = 0x1000;
switch (v)
{
case SymbolTypes::LEICHTER_TREFFER:
case SymbolTypes::MITTLERER_TREFFER:
case SymbolTypes::SCHWERER_TREFFER:
ret.insert(idBase); // SymbolId fuer die XML-Files
break;
case SymbolTypes::BEWEGUNGSUNFAEHIG:
case SymbolTypes::BEWEGUNGSUNFAEHIG_SICHTB:
ret.insert(idBase + 1);
break;
case SymbolTypes::AUSFALL_WAFFENANLAGE:
case SymbolTypes::AUSFALL_WAFFENANLAGE_SICHTB:
ret.insert(idBase + 2);
break;
case SymbolTypes::TOTALAUSFALL:
ret.insert(idBase + 1);
ret.insert(idBase + 2);
break;
default:
// die restlichen Alternativen fuehren zu keiner ID
break;
}
return ret;
}
static SymbolTable::SymbolId_Cont_T getModifierSymbolIDs(const SymbolTypes::modifier_struct &modifier)
{
SymbolId_Cont_T ret;
constexpr int idBase = 0x1010;
if (modifier.hasManipulation())
ret.insert(idBase + 1);
if (modifier.hasNoPosition())
ret.insert(idBase + 2);
if (modifier.hasByteError())
ret.insert(idBase + 4);
if (modifier.hasNbcProtection())
ret.insert(0x1003); // no dependency to idBase
return ret;
}
/**
Rotate all Primitives of all Symbols.
*/
void rotateAllSymbolPrimitives();
bool contains(int key) const;
int size() const;
void clear();
protected:
//! NGLLogger
NGL::INGLLogger& logger;
/**
Load a Symbol from a xml-file
\param filename: The xml-file to load
\param replace: if true, replaces old value(s), otherwise uses insertMulti
\return true on success, false if the Symbol could not be loaded
*/
bool loadSymbolFromFile(const QString &filename, bool replace = false);
QMap<int, Symbol*> m_map;
//! database table to read symbols from
QString m_databaseTable;
//! directory to read symbols from
QString m_directory;
}; // class SymbolTable
} // namespace SymbologyXML