This example demonstrates how to initialize, use, and extend the vrvMilStd 2525D / APP-6D symbology library from a VR-Vantage plugin.
Eight 2D symbol widgets are placed on the Ground_DB II terrain, representing a gallery of entity types across the Air, Land Unit, Land Equipment, Sea Surface, and Sea Subsurface symbol sets. A toolbar provides six interactive buttons that exercise the key rendering parameters in real time.
Unlike the standard vrvMilStd plugin, this example manually performs the full vrvMilStd initialization sequence in init() so that each step is visible and overridable.
After the manager is registered, the plugin connects a one-shot signal_postInitialize slot. When the display engine finishes initialization the manager's own slot_postInitialize() has already run (it was connected first in the manager constructor), so the plugin slot only needs to create and start the driver:
DtMilStdSymbolDriver::onTick() defers widget creation until the manager reports isInitialized(), which guarantees that the texture atlases are ready. On the first tick after initialization the driver switches to Plan View, then creates one DtSceneObjectAgent / DtProjectedWidgetModelAgent / DtWidgetLabelAgent triple per symbol:
The virtual texture key that drives each widget is produced by the manager interface:
DtExampleMilStdRenderer overrides render() to inject a red diamond into the SVG of every Hostile symbol, demonstrating the createRenderer() factory override point in DtMilStdManager:
This example is a plug-in. You can run it by running ./bin64/exampleMilStdSymbology_stealth.bat (on Windows from cmd.exe) or ./bin64/exampleMilStdSymbology_stealth.sh (on Linux). For more information about running examples, please see Running Applications and Examples.
#include <vrvCore/DtSceneObjectAgent.hpp>
#include <vrvCore/DtProjectedWidgetModelAgent.hpp>
#include <vrvCore/DtWidgetLabelAgent.hpp>
namespace DtExampleMilStd
{
static const DtMilStdSymbolDriver::SymbolDef theSymbolDefs[] = {
{"Fighter (Friend)", 1, 2, 225, 1, 0, 0, 0, 1, "1:2:225:1:-1:-1:-1", DtVector(-225.0, -75.0, 200.0)},
{"Attack Helo (Friend)", 1, 2, 225, 20, 0, 0, 0, 1, "1:2:225:20:-1:-1:-1", DtVector(-75.0, -75.0, 200.0)},
{"Tank M1A2 (Friend)", 1, 1, 225, 1, 0, 0, 0, 1, "1:1:225:1:-1:-1:-1", DtVector(75.0, -75.0, 20.0)},
{"IFV Bradley (Friend)", 1, 1, 225, 2, 1, 0, 0, 1, "1:1:225:2:1:-1:-1", DtVector(225.0, -75.0, 20.0)},
{"Destroyer DDG (Friend)", 1, 3, 225, 4, 0, 0, 0, 1, "1:3:225:4:-1:-1:-1", DtVector(-225.0, 75.0, 0.0)},
{"Submarine (Hostile)", 1, 4, 225, 3, 0, 0, 0, 2, "1:4:225:3:-1:-1:-1", DtVector(-75.0, 75.0, 0.0)},
{"Artillery SP (Neutral)", 1, 1, 225, 4, 0, 0, 0, 3, "1:1:225:4:-1:-1:-1", DtVector(75.0, 75.0, 20.0)},
{"Cargo Ship (Neutral)", 1, 3, 225, 80, 0, 0, 0, 3, "1:3:225:80:-1:-1:-1", DtVector(225.0, 75.0, 0.0)}};
static const int theSymbolCount = static_cast<int>(sizeof(theSymbolDefs) / sizeof(theSymbolDefs[0]));
static const char* theStarSvg = "<svg xmlns=\"http://www.w3.org/2000/svg\""
" width=\"100\" height=\"100\" viewBox=\"0 0 100 100\">"
"<rect width=\"100\" height=\"100\" fill=\"none\" stroke=\"none\"/>"
"<polygon"
" points=\"50,10 61,35 90,35 67,57 76,82 50,65 24,82 33,57 10,35 39,35\""
" fill=\"#ffd700\" stroke=\"#333333\" stroke-width=\"2\"/>"
"</svg>";
static const char* theCircleSvg = "<svg xmlns=\"http://www.w3.org/2000/svg\""
" width=\"100\" height=\"100\" viewBox=\"0 0 100 100\">"
"<circle cx=\"50\" cy=\"50\" r=\"40\""
" fill=\"#4488ff\" stroke=\"#222222\" stroke-width=\"3\"/>"
"</svg>";
static const char* theOverridePattern = "1:2:225:1:-1:-1:-1";
: DtDriver(am, "DtMilStdSymbolDriver")
, myMgr(mgr)
{
[this]( auto standard )
{
for ( auto& s : mySymbols )
{
rebuildKey( s );
}
} ) );
[this]( auto colorByForce )
{
for ( auto& s : mySymbols )
{
rebuildKey( s );
}
} ) );
[this]( auto forceId, auto color, auto enabled )
{
for ( auto& s : mySymbols )
{
rebuildKey( s );
}
} ) );
}
DtMilStdSymbolDriver::~DtMilStdSymbolDriver()
{
DtMilStdSymbolDriver::onStop();
}
const std::string& DtMilStdSymbolDriver::className() const
{
static std::string theName = "DtMilStdSymbolDriver";
return theName;
}
bool DtMilStdSymbolDriver::onStart()
{
std::string groundDb = myAgentManager.de().dePathConfiguration().sharedDataPath();
groundDb += "/TerrainData/TerrainConfiguration/Ground_DB II.mtf";
if (obs)
{
}
return true;
}
bool DtMilStdSymbolDriver::onStop()
{
for (auto& s : mySymbols)
{
reportElementDestroyed(s.myElementId);
s.myPwma->removeWidget(s.myLabel);
delete s.myLabel;
s.myLabel = nullptr;
s.mySceneObj->removeModel(s.myPwma);
delete s.myPwma;
s.myPwma = nullptr;
delete s.mySceneObj;
s.mySceneObj = nullptr;
}
mySymbols.clear();
return true;
}
static unsigned long long theFrameNum = 0;
bool DtMilStdSymbolDriver::onTick()
{
{
return true;
}
if (mySymbols.empty())
{
theFrameNum = myAgentManager.de().currentFrameNumber();
mySymbols.reserve(theSymbolCount + 1);
for (int i = 0; i < theSymbolCount; ++i)
{
const SymbolDef& def = theSymbolDefs[i];
const std::string sidc = iface.
generateSIDC(def.myKind, def.myDomain, def.myCountry, def.myCategory,
def.mySubcategory, def.mySpecific, def.myExtra, def.myForceId);
DtInfo << "[exampleMilStdSymbology] " << def.myName << " -> SIDC " << sidc << std::endl;
DtInfo << "[exampleMilStdSymbology] " << def.myName << " key=" << key << std::endl;
if (i == 0)
{
std::string svg;
DtInfo << "[exampleMilStdSymbology] SVG for " << def.myName << " (first " << static_cast<int>(svg.size())
<< " chars):\n"
<< svg << std::endl;
}
LiveSymbol ls;
ls.myDef = &def;
ls.mySidc = sidc;
ls.myParams = params;
ls.myElementId = myAgentManager.createNewUniqueId();
ls.mySceneObj = makVrv::DtSceneObjectAgent::create(myAgentManager);
ls.myPwma = makVrv::DtProjectedWidgetModelAgent::create(myAgentManager);
if (!ls.mySceneObj || !ls.myPwma || !ls.myLabel)
{
DtWarn << "[exampleMilStdSymbology] Failed to create agents for " << def.myName << std::endl;
delete ls.myLabel;
delete ls.myPwma;
delete ls.mySceneObj;
continue;
}
ls.mySceneObj->setElementID(ls.myElementId);
ls.mySceneObj->setPosition(0, def.myWorldPos);
ls.myLabel->setColor(1, 1, 1, 1);
ls.myLabel->setSize(symbolSz, renderH);
ls.myLabel->setEventsEnabled(true);
ls.myLabel->setBackgroundImage(key);
ls.myPwma->addWidget(ls.myLabel);
mySymbols.push_back(std::move(ls));
}
{
LiveSymbol ls;
ls.myDef = nullptr;
ls.myElementId = myAgentManager.createNewUniqueId();
ls.mySceneObj = makVrv::DtSceneObjectAgent::create(myAgentManager);
ls.myPwma = makVrv::DtProjectedWidgetModelAgent::create(myAgentManager);
ls.myLabel = makVrv::DtWidgetLabelAgent::create(myAgentManager);
if (ls.mySceneObj && ls.myPwma && ls.myLabel)
{
ls.mySceneObj->setElementID(ls.myElementId);
ls.mySceneObj->setPosition(0, DtVector(75.0, 225.0, 200.0));
ls.myLabel->setColor(1, 1, 1, 1);
ls.myLabel->setSize(100, 100);
ls.myLabel->setEventsEnabled(false);
ls.myLabel->setRasterSize(120, 120);
ls.myLabel->setSvgSource(theCircleSvg);
ls.myPwma->addWidget(ls.myLabel);
mySymbols.push_back(std::move(ls));
DtInfo << "[exampleMilStdSymbology] Created SVG widget (blue circle via setSvgSource)." << std::endl;
}
else
{
delete ls.myLabel;
delete ls.myPwma;
delete ls.mySceneObj;
}
}
}
if (myAgentManager.de().currentFrameNumber() == theFrameNum + 1)
{
for (auto& s : mySymbols)
{
if (s.myDef)
{
rebuildKey(s);
}
}
}
return true;
}
void DtMilStdSymbolDriver::rebuildKey(LiveSymbol& s)
{
if (!s.myDef)
{
return;
}
const int context = myExerciseActive ? 1 : 0;
const int status = myPlannedActive ? 1 : 0;
s.myDef->myKind,
s.myDef->myDomain,
s.myDef->myCountry,
s.myDef->myCategory,
s.myDef->mySubcategory,
s.myDef->mySpecific,
s.myDef->myExtra,
s.myDef->myForceId,
context,
status,
0,
0,
standard);
params.
myAlphaOverride = myGhostActive ?
static_cast<uint8_t
>(0x80) : static_cast<uint8_t>(0xFF);
s.myDef->myKind, s.myDef->myDomain, s.myDef->myCountry,
s.myDef->myCategory, s.myDef->mySubcategory, s.myDef->mySpecific,
s.myDef->myExtra, s.myDef->myForceId);
s.myParams = params;
s.myLabel->setColor(1.0, 1.0, 1.0, 1.0);
s.myLabel->setBackgroundImage(key);
}
void DtMilStdSymbolDriver::toggleGhostAlpha()
{
myGhostActive = !myGhostActive;
DtInfo << "[exampleMilStdSymbology] Ghost alpha: "
<< (myGhostActive ? "ON (128/255 = 50% opacity)" : "OFF (255/255 = fully opaque)") << std::endl;
for (auto& s : mySymbols)
{
rebuildKey(s);
}
}
void DtMilStdSymbolDriver::togglePlannedStatus()
{
myPlannedActive = !myPlannedActive;
DtInfo << "[exampleMilStdSymbology] Status: " << (myPlannedActive ? "Planned (dashed frame)" : "Present") << std::endl;
for (auto& s : mySymbols)
{
rebuildKey(s);
}
}
void DtMilStdSymbolDriver::toggleExerciseContext()
{
myExerciseActive = !myExerciseActive;
DtInfo << "[exampleMilStdSymbology] Context: " << (myExerciseActive ? "Exercise (letter decorator)" : "Reality") << std::endl;
for (auto& s : mySymbols)
{
rebuildKey(s);
}
}
void DtMilStdSymbolDriver::toggleApp6D()
{
myApp6DActive = !myApp6DActive;
DtInfo << "[exampleMilStdSymbology] Standard: " << (myApp6DActive ? "APP-6D (NATO)" : "2525D (US)") << std::endl;
for (auto& s : mySymbols)
{
rebuildKey(s);
}
}
void DtMilStdSymbolDriver::addOverride()
{
for (auto& s : mySymbols)
{
rebuildKey(s);
}
DtInfo << "[exampleMilStdSymbology] Override ADDED: Fighter now shows gold star." << std::endl;
}
void DtMilStdSymbolDriver::removeOverride()
{
for (auto& s : mySymbols)
{
rebuildKey(s);
}
DtInfo << "[exampleMilStdSymbology] Override REMOVED: Fighter reverts to MIL-STD icon." << std::endl;
}
}
#include <QtWidgets/QToolBar>
#include <QtWidgets/QAction>
namespace DtExampleMilStd
{
: DtToolbar( de, "DtMilStdSymbolToolbar" )
, myDe( de )
{
}
DtMilStdSymbolToolbar::~DtMilStdSymbolToolbar()
{
}
void DtMilStdSymbolToolbar::setDriver( DtMilStdSymbolDriver* driver )
{
myDriver = driver;
}
{
bar->setWindowTitle( QObject::tr( "MIL-STD Symbology" ) );
bar->setObjectName( "DtMilStdSymbolToolbar" );
QAction* ghostAction = bar->addAction( QObject::tr(
"Ghost Alpha" ) );
ghostAction->setCheckable( true );
ghostAction->setToolTip( QObject::tr(
"Toggle alpha override: 128/255 = 50% opacity (ghost state)" ) );
QObject::connect( ghostAction, &QAction::triggered,
[this]( bool ) { if ( myDriver ) { myDriver->toggleGhostAlpha(); } } );
bar->addSeparator();
QAction* plannedAction = bar->addAction( QObject::tr(
"Planned" ) );
plannedAction->setCheckable( true );
plannedAction->setToolTip( QObject::tr(
"Toggle status: Planned (dashed frame) vs Present" ) );
QObject::connect( plannedAction, &QAction::triggered,
[this]( bool ) { if ( myDriver ) { myDriver->togglePlannedStatus(); } } );
QAction* exerciseAction = bar->addAction( QObject::tr(
"Exercise" ) );
exerciseAction->setCheckable( true );
exerciseAction->setToolTip( QObject::tr(
"Toggle context: Exercise (X/J/K letter decorator) vs Reality" ) );
QObject::connect( exerciseAction, &QAction::triggered,
[this]( bool ) { if ( myDriver ) { myDriver->toggleExerciseContext(); } } );
bar->addSeparator();
QAction* app6Action = bar->addAction( QObject::tr(
"APP-6D" ) );
app6Action->setCheckable( true );
app6Action->setToolTip( QObject::tr(
"Toggle standard: APP-6D (NATO) vs 2525D (US)" ) );
QObject::connect( app6Action, &QAction::triggered,
[this]( bool ) { if ( myDriver ) { myDriver->toggleApp6D(); } } );
bar->addSeparator();
QAction* addOvrAction = bar->addAction( QObject::tr(
"Add Override" ) );
addOvrAction->setToolTip( QObject::tr(
"Replace Fighter aircraft with a custom gold-star SVG override" ) );
QObject::connect( addOvrAction, &QAction::triggered,
[this]( bool ) { if ( myDriver ) { myDriver->addOverride(); } } );
QAction* rmOvrAction = bar->addAction( QObject::tr(
"Remove Override" ) );
rmOvrAction->setToolTip( QObject::tr(
"Remove the custom SVG override; Fighter reverts to MIL-STD icon" ) );
QObject::connect( rmOvrAction, &QAction::triggered,
[this]( bool ) { if ( myDriver ) { myDriver->removeOverride(); } } );
return bar;
}
}