![]() |
VR-Forces 4.0.4 Class Documentation
|
/****************************************************************************** ** Copyright (c) 2012 MAK Technologies, Inc. ** All rights reserved. ******************************************************************************/ /****************************************************************************** ** $RCSfile: guiObjectDataConsole.h,v $ $Revision: 1.2 $ $State: Exp $ ******************************************************************************/ //\file guiObjectDataConsole.h #pragma once #include <vrvUtil/signalslib.h> #include <vrvCore/DtUniqueID.h> #include <QtGui/QDialog> #include <vrfGuiCore/DtEntityDataInterface.h> #include <vrfGuiCore/DtAggregateDataInterface.h> #include <vrfGuiCore/DtSpotReportDataInterface.h> #include <vrfGuiCore/DtTacticalGraphicDataInterface.h> namespace makVrv { class DtDe; } //The DtGuiObjectDataConsole class will allow for the entering of an object name //or element id to retrieve information about that object class DtVector; class QVBoxLayout; class QTextEdit; class QLineEdit; class QRadioButton; class DtGuiObjectDataConsole : public QDialog { Q_OBJECT public: DtGuiObjectDataConsole(makVrv::DtDe& de, QWidget* parent); virtual ~DtGuiObjectDataConsole(); protected: //Prints a line of text to the console window. Will add CR/LF virtual void print(const QString&); //Displays information for the tactical graphics virtual void displaySpotReportInformation(makVrf::DtSpotReportDataInterfacePtr); //Displays information for the tactical graphics virtual void displayTacticalGraphicInformation(makVrf::DtTacticalGraphicDataInterfacePtr); //Displays information for the aggregate virtual void displayAggregateInformation(makVrf::DtAggregateDataInterfacePtr); //Displays information for the entity virtual void displayEntityInformation(makVrf::DtEntityDataInterfacePtr); //Shows help for the console virtual void help(); //Shows information for the given item virtual void info(const QString&); //Shows spot report information for the given item (if it exists) virtual void spotinfo(const QString&); //Returns the network data interface for given item virtual DtBoost::shared_ptr<makVrf::DtObjectDataInterface> lookupObjectData(const QString&) const; //Hides the specified object virtual void hideObject(const QString&); //Shows the specified object virtual void showObject(const QString&); //Adds the object to the selection virtual void selectObject(const QString&); //Removes the object from the current selection virtual void removeFromSelection(const QString&); protected: //Returns a list of names from the given element ids virtual QString namesFrom(const std::vector<makVrv::DtElementID>& ids) const; //Displays information for the entity, along with resource information. This call will //delete the interface when complete virtual void displayEntityInformationWithResources(makVrf::DtEntityDataInterfacePtr); protected slots: //Called when return is pressed in the object widget. Will then try and find //information for that object virtual void processObject(); protected: makVrv::DtDe& myDe; QRadioButton* myLocal; QRadioButton* myGeocentric; QVBoxLayout* myMainLayout; QTextEdit* myConsole; //The output of the command QLineEdit* myObject; //Object input };
guiObjectDataConsole.cxx
/****************************************************************************** ** Copyright (c) 2012 MAK Technologies, Inc. ** All rights reserved. ******************************************************************************/ /****************************************************************************** ** $RCSfile: guiObjectDataConsole.cxx,v $ $Revision: 1.2 $ $State: Exp $ ******************************************************************************/ //\file guiObjectDataConsole.cxx #include "guiObjectDataConsole.h" #include <vrvCore/DtDe.h> #include <vrfGuiCore/DtVrfStateViewCollectionManager.h> #include <vrfGuiCore/DtEntityDataInterface.h> #include <vrfGuiCore/DtAggregateDataInterface.h> #include <vrfGuiCore/DtSpotReportDataInterface.h> #include <vrfGuiCore/DtTacticalGraphicDataInterface.h> #include <vrfGuiCore/DtVrfSpotReportManager.h> #include <QtGui/QTextEdit> #include <QtGui/QLineEdit> #include <QtGui/QLayout> #include <QtGui/QLabel> #include <QtGui/QRadioButton> using namespace makVrv; using namespace makVrf; DtGuiObjectDataConsole::DtGuiObjectDataConsole(makVrv::DtDe& de, QWidget* parent) : 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); } DtGuiObjectDataConsole::~DtGuiObjectDataConsole() { } 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; } void DtGuiObjectDataConsole::displayTacticalGraphicInformation(DtTacticalGraphicDataInterfacePtr 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("Entity ID: ") + info->entityId().c_str()); print(QString("Global ID: ") + info->globalId().c_str()); print(QString("Type: ") + info->entityType().c_str()); 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); } } void DtGuiObjectDataConsole::displaySpotReportInformation(DtSpotReportDataInterfacePtr 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("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")); } void DtGuiObjectDataConsole::displayEntityInformationWithResources(DtEntityDataInterfacePtr info) { displayEntityInformation(info); 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)); } void DtGuiObjectDataConsole::displayEntityInformation(DtEntityDataInterfacePtr 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().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")); 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"); } } void DtGuiObjectDataConsole::displayAggregateInformation(DtAggregateDataInterfacePtr info) { displayEntityInformation(info); 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()); } void DtGuiObjectDataConsole::help() { 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"); } void DtGuiObjectDataConsole::processObject() { 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") { removeFromSelection(name); } myObject->setText(""); return; } 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(name.toLatin1().constData()); } return iface; } void DtGuiObjectDataConsole::spotinfo(const QString& name) { DtElementID id = name.toLongLong(); DtObjectDataInterfacePtr iface; if (id != 0) { iface = DtVrfStateViewCollectionManager::instance(myDe).lookupSpotReportData(id); } else { iface = DtVrfStateViewCollectionManager::instance(myDe).lookupSpotReportData(name.toLatin1().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) { DtObjectDataInterfacePtr iface = lookupObjectData(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()) { displayEntityInformation(eface); } else { eface->signal_resourcesChanged.connect(boost::bind(&DtGuiObjectDataConsole::displayEntityInformationWithResources, this, eface)); return; } } else if (iface->type() == DtElementEntry::Aggregate) { displayAggregateInformation( DtObjectDataInterface::cast<DtAggregateDataInterface>(iface)); } else if (iface->type() == DtElementEntry::TacticalGraphic) { displayTacticalGraphicInformation( DtObjectDataInterface::cast<DtTacticalGraphicDataInterface>(iface)); } } void DtGuiObjectDataConsole::hideObject(const QString& name) { DtObjectDataInterfacePtr iface = lookupObjectData(name); if (!iface) { print("Could not find information for requested object"); return; } iface->setVisible(false); } void DtGuiObjectDataConsole::showObject(const QString& name) { DtObjectDataInterfacePtr iface = lookupObjectData(name); if (!iface) { print("Could not find information for requested object"); return; } iface->setVisible(true); } void DtGuiObjectDataConsole::selectObject(const QString& name) { DtObjectDataInterfacePtr iface = lookupObjectData(name); if (!iface) { print("Could not find information for requested object"); return; } iface->addToSelection(); } void DtGuiObjectDataConsole::removeFromSelection(const QString& name) { DtObjectDataInterfacePtr iface = lookupObjectData(name); if (!iface) { print("Could not find information for requested object"); return; } iface->removeFromSelection(); }