VR-Forces 5.0.3 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GUI Object Data Interface (guiObjectDataInterface)

Table of Contents

The GUI Object Data Interface example demonstrates how to access data for entities, aggregates and environmental objects.

It shows:

Accessing Object Data Interface and DtVrfStateViewCollectionManager

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.

How to Run the Example

Usage

In the Launcher, click the Plug-ins button to bring up the Plug-ins Selection dialog. Enable the plugin.

To view the new behavior:

  1. Start VR-Forces GUI and SIM.
  2. Load an existing scenario - e.g. HawaiiGround.scnx.
  3. Alternatively - you can start just vrfGui and connect to an already running vrfSim with a loaded scenario.
  4. Choose 'Data Interface' menu item.
  5. Select the 'Data Console...' menu sub-item
  6. The data console (Object Information window) is displayed.
  7. Type help to retrieve the available commands. Then type a command to display information about a published item

Classes

DtObjectDataInterfaceMenuItemThe menu item to display the console.
DtGuiObjectDataConsoleThe console used to retrieve and display information about published items.

Plugin Entry Points

/******************************************************************************
** Copyright (c) 2012 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
/******************************************************************************
** $RCSfile: guiObjectDataConsole.cxx,v $ $Revision: 1.2 $ $State: Exp $
******************************************************************************/
//\file guiObjectDataConsole.cxx
#include <vrvCore/DtDe.h>
#include <QtWidgets/QTextEdit>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QRadioButton>
using namespace makVrv;
using namespace makVrf;
: QDialog(parent, Qt::Tool)
, myDe(de)
{
//Create the GUI for the console and the command entry
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);
QLabel* label = new QLabel(tr("Output"), this);
myMainLayout->addWidget(label);
myConsole = new QTextEdit(this);
myConsole->setReadOnly(true);
myMainLayout->addWidget(myConsole);
label = new QLabel(tr("Object"), this);
myObject = new QLineEdit(this);
myMainLayout->addWidget(label);
myMainLayout->addWidget(myObject);
connect(myObject, SIGNAL(returnPressed()), this, SLOT(processObject()));
setWindowTitle(tr("Object Information"));
myObject->setFocus();
resize(500, 400);
}
{
}
void DtGuiObjectDataConsole::print(const QString& c)
{
myConsole->insertPlainText(c + "\r\n");
}
QString DtGuiObjectDataConsole::namesFrom(const std::vector<DtElementID>& ids) const
{
QString res;
unsigned i;
for (i = 0; i < ids.size(); i++)
{
if (res.length())
{
res += ", ";
}
DtVrfVrlinkDataInterfacePtr iface = DtObjectDataInterface::cast<DtVrfVrlinkDataInterface>(
lookupObjectData(QString::number(ids[i])));
if (iface)
{
res += iface->name().c_str();
// delete iface;
}
}
return res;
}
{
DtObjectDataInterface::Representation rep = (myLocal->isChecked() ? DtObjectDataInterface::Local : DtObjectDataInterface::World);
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(res);
}
}
{
DtObjectDataInterface::Representation rep = (myLocal->isChecked() ? DtObjectDataInterface::Local : DtObjectDataInterface::World);
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();
print("Resources:");
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 += ")";
print(res);
++iter;
}
info->signal_resourcesChanged.disconnect(boost::bind(&DtGuiObjectDataConsole::displayEntityInformationWithResources, this, info));
}
{
DtObjectDataInterface::Representation rep = (myLocal->isChecked() ? DtObjectDataInterface::Local : DtObjectDataInterface::World);
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"));
DtElementID embarkedOn = info->embarkedOn();
if (embarkedOn != 0)
{
DtVrfVrlinkDataInterfacePtr iface = DtObjectDataInterface::cast<DtVrfVrlinkDataInterface>(
lookupObjectData(QString::number(embarkedOn)));
if (iface)
{
print(QString("Emarked On: ") + iface->name().c_str());
}
}
std::vector<DtElementID> emb = info->objectsEmbarked();
if (emb.size())
{
QString res;
res = "Objects Embarked: " + namesFrom(emb);
print(res);
}
DtElementID superior = info->superior();
if (superior != 0)
{
DtVrfVrlinkDataInterfacePtr iface = DtObjectDataInterface::cast<DtVrfVrlinkDataInterface>(
lookupObjectData(QString::number(superior)));
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;
res = "Subordinates: " + namesFrom(emb);
print(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(' ');
myConsole->clear();
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")
{
info(name);
}
else if (lst[0].toLower() == "spotinfo")
{
spotinfo(name);
}
else if (lst[0].toLower() == "hide")
{
hideObject(name);
}
else if (lst[0].toLower() == "show")
{
showObject(name);
}
else if (lst[0].toLower() == "select")
{
selectObject(name);
}
else if (lst[0].toLower() == "remove")
{
}
myObject->setText("");
return;
}
myObject->setText("");
help();
}
DtBoost::shared_ptr<DtObjectDataInterface> DtGuiObjectDataConsole::lookupObjectData(const QString& name) const
{
DtElementID id = name.toLongLong();
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;
}
void DtGuiObjectDataConsole::spotinfo(const QString& name)
{
DtElementID id = name.toLongLong();
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->type() == SpotReportsElementType)
{
displaySpotReportInformation(DtObjectDataInterface::cast<DtSpotReportDataInterface>(iface));
}
}
void DtGuiObjectDataConsole::info(const QString& name)
{
if (!iface)
{
print("Could not find information for requested object");
return;
}
if (iface->type() == DtElementEntry::Entity)
{
DtEntityDataInterfacePtr eface = DtObjectDataInterface::cast<DtEntityDataInterface>(iface);
if (eface->resources().size())
{
}
else
{
eface->signal_resourcesChanged.connect(boost::bind(&DtGuiObjectDataConsole::displayEntityInformationWithResources, this, eface));
return;
}
}
else if (iface->type() == DtElementEntry::Aggregate)
{
DtObjectDataInterface::cast<DtAggregateDataInterface>(iface));
}
else if (iface->type() == DtElementEntry::TacticalGraphic)
{
DtObjectDataInterface::cast<DtTacticalGraphicDataInterface>(iface));
}
}
void DtGuiObjectDataConsole::hideObject(const QString& name)
{
if (!iface)
{
print("Could not find information for requested object");
return;
}
iface->setVisible(false);
}
void DtGuiObjectDataConsole::showObject(const QString& name)
{
if (!iface)
{
print("Could not find information for requested object");
return;
}
iface->setVisible(true);
}
void DtGuiObjectDataConsole::selectObject(const QString& name)
{
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();
}

Document ID: Generated on Thu Jun 1 17:58:13 EDT 2023 from SVN revision 255404
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)