The GUI Object Data Interface example demonstrates how to access data for entities, aggregates and environmental objects.
The network data interface (and its subclasses) give developers access to simulation level information (location, orientation, resources, etc.) in a single, convenient object. This example shows how to use the DtVrfStateViewCollectionManager to request a data interface object by marking text, and, how to use that object to retrieve information about that object.
This example creates a console that allows for entering of simple commands to retrieve information by name of object or by unique ID and then displays information for that object in the console.
In the Launcher, click the Plug-ins button to bring up the Plug-ins Selection dialog. Enable the plugin.
#include <QtWidgets/QTextEdit>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QRadioButton>
using namespace makVrv;
using namespace makVrf;
, myDe(de)
{
myMainLayout = new QVBoxLayout(this);
myMainLayout->setContentsMargins(2, 2, 2, 2);
QHBoxLayout* hLay = new QHBoxLayout;
hLay->setContentsMargins(2, 2, 2, 2);
myLocal = new QRadioButton(tr("Local"), this);
myLocal->setChecked(true);
myGeocentric = new QRadioButton(tr("World"), this);
hLay->addWidget(myLocal);
hLay->addWidget(myGeocentric);
myMainLayout->addLayout(hLay);
myMainLayout->addWidget(label);
myConsole = new QTextEdit(this);
myConsole->setReadOnly(true);
myMainLayout->addWidget(myConsole);
label =
new QLabel(tr(
"Object"),
this);
myMainLayout->addWidget(label);
myMainLayout->addWidget(myObject);
connect(myObject, SIGNAL(returnPressed()), this, SLOT(processObject()));
setWindowTitle(tr("Object Information"));
myObject->setFocus();
resize(500, 400);
}
{
}
{
}
{
QString res;
unsigned i;
for (i = 0; i < ids.size(); i++)
{
if (res.length())
{
res += ", ";
}
if (iface)
{
res += iface->
name().c_str();
}
}
return res;
}
{
print(QString(
"Element ID: ") + QString::number(info->elementID()));
print(QString(
"Name: ") + info->name().c_str());
print(QString(
"Entity ID: ") + info->entityId().c_str());
print(QString(
"Global ID: ") + info->globalId().c_str());
print(QString(
"Type: ") + info->entityType().string());
std::vector<DtVector> locations = info->locations(rep);
if (locations.size())
{
QString res = "Locations: ";
int iLimit = locations.size();
int i;
for (i = 0; i < iLimit; i++)
{
if (i != 0)
{
res += ", ";
}
res += locations[i].string().c_str();
}
}
}
{
print(QString(
"Element ID: ") + QString::number(info->elementID()));
print(QString(
"Name: ") + info->name().c_str());
print(QString(
"Type: ") + info->entityType().c_str());
print(QString(
"Location: ") + info->location(rep).string().c_str());
print(QString(
"Velocity: ") + info->velocity(rep).string().c_str());
print(QString(
"Acceleration: ") + info->acceleration(rep).string().c_str());
print(QString(
"Orientation: ") + info->orientation(rep).string().c_str());
print(QString(
"Heading: ") + QString::number(info->heading()));
print(QString(
"Visible: ") + (info->isVisible() ?
"True" :
"False"));
print(QString(
"Selected: ") + (info->isSelected() ?
"True" :
"False"));
}
{
DtVrfDataInterraceResourceRequestor::ResourceMap::const_iterator iter = info->resources().begin();
while (iter != info->resources().end())
{
QString res = iter->second.myResourceName.c_str();
res += ": ";
res += QString::number(iter->second.myCurrentAmount);
res += " (";
res += QString::number(iter->second.myFullAmount);
res += ")";
++iter;
}
}
{
print(QString(
"Element ID: ") + QString::number(info->elementID()));
print(QString(
"Name: ") + info->name().c_str());
print(QString(
"Label: ") + info->label().c_str());
print(QString(
"Entity ID: ") + info->entityId().c_str());
print(QString(
"Global ID: ") + info->globalId().c_str());
print(QString(
"Type: ") + info->entityType().string());
print(QString(
"Location: ") + info->location(rep).string().c_str());
print(QString(
"Velocity: ") + info->velocity(rep).string().c_str());
print(QString(
"Acceleration: ") + info->acceleration(rep).string().c_str());
print(QString(
"Orientation: ") + info->orientation(rep).string().c_str());
print(QString(
"Heading: ") + QString::number(info->heading()));
print(QString(
"Visible: ") + (info->isVisible() ?
"True" :
"False"));
print(QString(
"Selected: ") + (info->isSelected() ?
"True" :
"False"));
if (embarkedOn != 0)
{
if (iface)
{
print(QString(
"Emarked On: ") + iface->name().c_str());
}
}
std::vector<DtElementID> emb = info->objectsEmbarked();
if (emb.size())
{
QString res;
}
if (superior != 0)
{
if (iface)
{
print(QString(
"Superior: ") + iface->name().c_str());
}
}
else
{
print(
"Superior: Force Level");
}
}
{
std::vector<DtElementID> emb = info->subordinates();
if (emb.size())
{
QString res;
}
print(QString(
"Dimensions: ") + info->dimensions().string().c_str());
print(QString(
"Formation: ") + info->formation().c_str());
}
{
print(
"info <name|id> - Shows information for object");
print(
"spotinfo <name|id> - Shows spot report information for object");
print(
"select <name|id> - Adds object to current selection");
print(
"remove <name|id> - Removes object from current selection");
print(
"hide <name|id> - Hides object");
print(
"show <name|id> - Shows object");
print(
"help - Shows this list");
}
{
QStringList lst =
myObject->text().split(
' ');
if (lst.count() >= 2)
{
QString name;
int i;
for (i = 1; i < lst.size(); i++)
{
if (i != 1)
{
name += " ";
}
name += lst[i];
}
if (lst[0].toLower() == "info")
{
}
else if (lst[0].toLower() == "spotinfo")
{
}
else if (lst[0].toLower() == "hide")
{
}
else if (lst[0].toLower() == "show")
{
}
else if (lst[0].toLower() == "select")
{
}
else if (lst[0].toLower() == "remove")
{
}
return;
}
}
{
DtBoost::shared_ptr<DtObjectDataInterface> iface;
if (id != 0)
{
iface = DtVrfStateViewCollectionManager::instance(myDe).lookupObjectData(id);
}
else
{
iface = DtVrfStateViewCollectionManager::instance(myDe).lookupObjectData(
DtUUID(name.toUtf8().constData()));
}
return iface;
}
{
if (id != 0)
{
iface = DtVrfStateViewCollectionManager::instance(myDe).lookupSpotReportData(id);
}
else
{
iface = DtVrfStateViewCollectionManager::instance(myDe).lookupSpotReportData(name.toUtf8().constData());
}
if (!iface)
{
print(
"Could not find spot report information");
return;
}
{
}
}
{
if (!iface)
{
print(
"Could not find information for requested object");
return;
}
{
if (eface->resources().size())
{
}
else
{
return;
}
}
else if (iface->type() == DtElementEntry::Aggregate)
{
DtObjectDataInterface::cast<DtAggregateDataInterface>(iface));
}
else if (iface->type() == DtElementEntry::TacticalGraphic)
{
DtObjectDataInterface::cast<DtTacticalGraphicDataInterface>(iface));
}
}
{
if (!iface)
{
print(
"Could not find information for requested object");
return;
}
iface->setVisible(false);
}
{
if (!iface)
{
print(
"Could not find information for requested object");
return;
}
iface->setVisible(true);
}
{
if (!iface)
{
print(
"Could not find information for requested object");
return;
}
iface->addToSelection();
}
{
if (!iface)
{
print(
"Could not find information for requested object");
return;
}
iface->removeFromSelection();
}