VR-Forces 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 Sim Object References and the DtVrfGuiSimObjectManager class

The front-end has been worked to allow access to objects with a similar API as the back-end, the DtSimObjectReference class. This class will encapsulate a DtGuiSimObject and can be accessed via the DtVrfGuiSimObjectManager. The API for this class is similar to the API of the back-end class of the same name. These objects are thread safe in the context that they can be accessed in a pre or post DtDe tick and do not need to have an update rate set to them. All usage of the the DtStateView, DtStateData and DtVrfStateViewCollectionManager have been removed.

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) 2024 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
//\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 += ", ";
}
DtSimObjectReference iface = lookupObjectData(QString::number(ids[i]));
if (iface.isValid())
{
res += QString::fromLocal8Bit(iface->objectName().c_str());
}
}
return res;
}
{
print(QString("Element ID: ") + QString::number(info->id()));
print(QString("Name: ") + info->objectName().c_str());
print(QString("Entity ID: ") + info->entityId().string());
print(QString("Global ID: ") + info->globalId().c_str());
print(QString("Type: ") + info->entityType().string());
std::vector<DtVector> locations;
if (myLocal->isChecked())
{
locations = info->getStateComponent<DtVrfGeometryStateComponent>()->localVertices().asVector();
}
else
{
locations = info->getStateComponent<DtVrfGeometryStateComponent>()->worldVertices().asVector();
}
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);
}
}
{
print(QString("Element ID: ") + QString::number(info->id()));
print(QString("Name: ") + info->objectName().c_str());
print(QString("Type: ") + info->entityType().string());
print(QString("Location: ") + (myLocal->isChecked() ? info->localPosition().string().c_str() : info->worldPosition().string().c_str()));
{
print(QString("Velocity: ") + (myLocal->isChecked() ? comp->localVelocity().string().c_str() : comp->worldVelocity().string().c_str()));
print(QString("Acceleration: ") + (myLocal->isChecked() ? comp->localAcceleration().string().c_str() : comp->worldAcceleration().string().c_str()));
print(QString("Orientation: ") + (myLocal->isChecked() ? comp->localOrientation().string().c_str() : comp->worldOrientation().string().c_str()));
print(QString("Heading: ") + QString::number(info->heading()));
}
print(QString("Visible: ") + (DtElementAttributeUtilityFunctions::isVisible(myDe, info->id()) ? "True" : "False"));
print(QString("Selected: ") + (DtSelectionManager::instance(myDe).isSelected(info->id()) ? "True" : "False"));
}
{
const makVrfEvents::DtResourceResponseEvent& resources = dynamic_cast<const makVrfEvents::DtResourceResponseEvent&>(iface->event());
if (resources.requestId() == myRequestId)
{
DtEnumDictionary* dict = DtVrfEntityTypeDictionaryManager::instance(myDe).dictionary();
for (const auto& resource : resources.resources())
{
print(QString("%1: %2/%3 (location %4)").arg(QString::fromUtf8(dict->displayName(resource.resourceType(), false, 6).c_str())).
arg(resource.currentAmount()).arg(resource.fullAmount()).arg(QString::fromUtf8(dict->enumNameFromValue(DtVrfResourceBinsUid, resource.bin()))));
}
}
}
{
myRequestId = DtGuiThreadVrfRemoteController::instance(myDe).generateRequestId();
DtGuiThreadVrfRemoteController::instance(myDe).requestResourcesFor({info->uuid()}, myRequestId);
}
{
print(QString("Element ID: ") + QString::number(info->id()));
print(QString("Name: ") + info->objectName().c_str());
print(QString("Label: ") + info->getStateComponent<DtVrfStateComponent>()->label().c_str());
print(QString("Entity ID: ") + info->entityId().string());
print(QString("Global ID: ") + info->globalId().c_str());
print(QString("Type: ") + info->entityType().string());
DtUUID hostGlobalId(DtUUID::nullUUID());
{
print(QString("Velocity: ") + (myLocal->isChecked() ? comp->localVelocity().string().c_str() : comp->worldVelocity().string().c_str()));
print(QString("Acceleration: ") + (myLocal->isChecked() ? comp->localAcceleration().string().c_str() : comp->worldAcceleration().string().c_str()));
print(QString("Orientation: ") + (myLocal->isChecked() ? comp->localOrientation().string().c_str() : comp->worldOrientation().string().c_str()));
print(QString("Heading: ") + QString::number(info->heading()));
hostGlobalId = comp->hostGlobalId();
}
print(QString("Heading: ") + QString::number(info->heading()));
print(QString("Visible: ") + (DtElementAttributeUtilityFunctions::isVisible(myDe, info->id()) ? "True" : "False"));
print(QString("Selected: ") + (DtSelectionManager::instance(myDe).isSelected(info->id()) ? "True" : "False"));
if (hostGlobalId.isValid())
{
DtSimObjectReference iface = DtVrfGuiSimObjectManager::instance(myDe).lookup(hostGlobalId);
if (iface.isValid())
{
print(QString("Emarked On: ") + iface->objectName().c_str());
}
}
const DtEmbarkationHierarchyStateAttribute* atr = DtElementAttributeUtilityFunctions::embarkationHierarchyState(myDe, info->id());
if (atr)
{
QString res;
res = "Objects Embarked: " + namesFrom(atr->value().children());
print(res);
}
const DtElementIDHierarchyStateAttribute* hierAtr = DtElementAttributeUtilityFunctions::echelonHierarchyState(myDe, info->id());
if (hierAtr && (hierAtr->value().parentId() != 0))
{
DtSimObjectReference iface = DtVrfGuiSimObjectManager::instance(myDe).lookup(hierAtr->value().parentId());
if (iface.isValid())
{
print(QString("Superior: ") + iface->objectName().c_str());
}
}
else
{
print("Superior: Force Level");
}
}
{
const DtElementIDHierarchyStateAttribute* atr = DtElementAttributeUtilityFunctions::echelonHierarchyState(myDe, info->id());
if (atr)
{
QString res;
res = "Subordinates: " + namesFrom(atr->value().children());
print(res);
}
Dt3dBoundingVolume bv = info->getStateComponent<DtVrfGeometryStateComponent>()->boundingGeometry().boundingVolume();
print(QString("Dimensions: ") + DtVector(bv.length(), bv.width(), bv.height()).string().c_str());
print(QString("Formation: ") + info->getStateComponent<DtAggregateStateComponent>()->formationName().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();
}
{
DtElementID id = name.toLongLong();
if (id != 0)
{
iface = DtVrfGuiSimObjectManager::instance(myDe).lookup(id);
}
else
{
iface = DtVrfGuiSimObjectManager::instance(myDe).lookup(DtUUID(name.toUtf8().constData()));
}
return iface;
}
void DtGuiObjectDataConsole::spotinfo(const QString& name)
{
DtSimObjectReference iface = DtSpotReportDataProcessor::instance(myDe).lookup(DtUUID(name.toUtf8().constData()));
if (!iface.isValid())
{
print("Could not find spot report information");
return;
}
if (iface->isSpotReport())
{
}
}
void DtGuiObjectDataConsole::info(const QString& name)
{
if (!iface.isValid())
{
print("Could not find information for requested object");
return;
}
if (iface->isUnit())
{
}
else if (iface->isEnvironmental())
{
}
else
{
}
}
void DtGuiObjectDataConsole::hideObject(const QString& name)
{
if (!iface.isValid())
{
print("Could not find information for requested object");
return;
}
DtDataBankSignaler::instance(myDe.mainEventQueue()).signal_elementAttributeChangeRequested(
iface->id(), iface->id(), std::shared_ptr<DtElementAttribute>(new DtElementAttributeVisibility(false)));
}
void DtGuiObjectDataConsole::showObject(const QString& name)
{
if (!iface.isValid())
{
print("Could not find information for requested object");
return;
}
DtDataBankSignaler::instance(myDe.mainEventQueue()).signal_elementAttributeChangeRequested(
iface->id(), iface->id(), std::shared_ptr<DtElementAttribute>(new DtElementAttributeVisibility(true)));
}
void DtGuiObjectDataConsole::selectObject(const QString& name)
{
if (!iface.isValid())
{
print("Could not find information for requested object");
return;
}
showSet.insert( iface->id() );
DtSelectionManager::instance( myDe ).addToCurrentSelection(showSet);
}
{
if (!iface.isValid())
{
print("Could not find information for requested object");
return;
}
showSet.insert( iface->id() );
DtSelectionManager::instance( myDe ).removeFromCurrentSelection(showSet);
}

Document ID: Generated on Thu Oct 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)