VR-Forces 4.7 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Entity List (entityListClass)

The DtEntityList class is a Qt-based dialog/ widget class that displays all existing entities as well as their current task and, if available, their destination.


Header file:

/*******************************************************************************
** Copyright (c) 2011 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
//\file DtEntityList.h
//\brief Contains makVrf::makVrfEntityListExample::DtEntityList class.
#pragma once
#include "entityListUi.hpp"
namespace makVrv
{
class DtDe;
}
namespace makVrfEntityListExample
{
//A widget class that displays all existing entities
//as well as their current task and, if available, their destination.
class DtEntityList
: public makVrv::DtPage
{
public:
DtEntityList( makVrv::DtDe& de, QWidget* parent = 0, Qt::WindowFlags flags = 0);
virtual ~DtEntityList();
//Get the icon of the page.
virtual QIcon icon();
//Get the title of the page.
virtual QString title();
//Get the class name of the page.
virtual const std::string& pageClassName() const;
//Called when the page is displayed.
virtual void activate();
//Called when the page is hidden.
virtual void deactivate();
static std::string thePageClassName();
//Goes through the entire list of entities and populates the tree
virtual void populateEntityList();
protected:
//Sets up the contents of the widget onto the supplied parent
void setupUi(QWidget* p);
//Clears out widget
virtual void clear();
protected:
virtual void slot_onCurrentTaskChanged(DtUUID entityName);
//Using the known task, fill in the destination line in the entity list
public:
Ui_DtEntityListUi myUi;
//A list of all simulated entities.
//Each State View is a collection of similar objects
//that the VR-Forces front end knows about. This particular view
//keeps a list of all simulated entities.
//This maps keeps track of each line in the target list
std::map<const makVrv::DtStateView<makVrv::DtVrlinkSimulatedEntityState>*, QTreeWidgetItem*> myLineToStateViewMap;
};
//Create a "creator" helper class using the template.
}

Implementation:

/*******************************************************************************
** Copyright (c) 2011 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
//\file DtEntityList.cxx
//\brief Contains makVrf3DEntityListExample::DtEntityList class.
#include "DtEntityList.h"
#include <vlpi/appearance.h>
#include <QtGui/QPixmap>
using namespace makVrf;
namespace makVrfEntityListExample
{
DtEntityList::DtEntityList( makVrv::DtDe& de, QWidget* parent, Qt ::WindowFlags flags)
: DtPage(de, parent, flags)
{
setObjectName(tr("Entity List"));
setupUi(this);
myUi.myEntityTree->setRootIsDecorated(false);
mySimulatedEntityStateView = DtVrfStateViewCollectionManager::instance(de).simulatedEntityStateViewCollection();
//The first thing to do is to populate my entity list with all existing entities.
populateEntityList();
//Set up connections
//From now on, all new entities are called through these slots.
mySimulatedEntityStateView->signal_stateViewAdded.connect(
boost::bind(&DtEntityList::slot_onObjectAdded, this, _1));
mySimulatedEntityStateView->signal_stateViewAboutToBeRemoved.connect(
boost::bind(&DtEntityList::slot_onObjectAboutToBeRemoved, this, _1));
DtVrfCurrentTaskManager& manager = DtVrfCurrentTaskManager::instance(de);
manager.signal_currentTaskChanged.connect(
boost::bind(&DtEntityList::slot_onCurrentTaskChanged, this, _1));
}
DtEntityList::~DtEntityList()
{
//remove connections
mySimulatedEntityStateView->signal_stateViewAdded.disconnect(
boost::bind(&DtEntityList::slot_onObjectAdded, this, _1));
mySimulatedEntityStateView->signal_stateViewAboutToBeRemoved.disconnect(
boost::bind(&DtEntityList::slot_onObjectAboutToBeRemoved, this, _1));
DtVrfCurrentTaskManager& manager = DtVrfCurrentTaskManager::instance(DtPage::myDe);
manager.signal_currentTaskChanged.disconnect(
boost::bind(&DtEntityList::slot_onCurrentTaskChanged, this, _1));
}
{
return QIcon();
// return QIcon(QString::fromStdString(DtPage::myDe.dePathConfiguration().dataPath() +"/Icons/?.svg"));
}
{
return tr("Entity List");
}
const std::string& DtEntityList::pageClassName() const
{
static std::string theClassName = "DtEntityList";
return theClassName;
}
{
}
{
}
std::string DtEntityList::thePageClassName()
{
return "DtEntityList";
}
void DtEntityList::setupUi(QWidget* p)
{
myUi.setupUi(this);
}
void DtEntityList::clear()
{
myUi.myEntityTree->clear();
}
void DtEntityList::populateEntityList()
{
//The list from the DtVrfStateViewCollectionManager will contain
//all the entities that are currently on the network. Initially,
//this function populates our list, but it gets updated by using the
//callback functions below
DtVrfSimulatedEntityStateViewCollection::StateViewMap::const_iterator iter =
mySimulatedEntityStateView->stateViewMap().begin();
while (iter != mySimulatedEntityStateView->stateViewMap().end())
{
//Add the entity to my list
slot_onObjectAdded(*entityState);
++iter;
}
}
void DtEntityList::slot_onObjectAdded(const makVrv::DtStateView<makVrv::DtVrlinkSimulatedEntityState>& entityState)
{
if(myLineToStateViewMap[nonConstStateView] != 0)
{
return; //This object has already been added.
}
QTreeWidgetItem* displayEntityItem = new QTreeWidgetItem(myUi.myEntityTree);
//Subscribe to object updates so we can grab the name of an entity when it updates.
//Note that it is possible that at this point the entity name is blank which is why
//we need to wait for an update.
nonConstStateView->signal_stateViewUpdated.connect(
boost::bind(&DtEntityList::slot_onObjectUpdated, this, _1));
//Set to update on any updates. Need to set update rate on state view in
//order to get state view information
//Force the initial update. Note that it is possible that this initial update is incomplete
myLineToStateViewMap[nonConstStateView] = displayEntityItem;
nonConstStateView->forceUpdate();
}
void DtEntityList::slot_onObjectAboutToBeRemoved(const makVrv::DtStateView<makVrv::DtVrlinkSimulatedEntityState>& entityState)
{
//Remove all callbacks
nonConstStateView->signal_stateViewUpdated.disconnect(
boost::bind(&DtEntityList::slot_onObjectUpdated, this, _1));
//Remove deleted entity from gui.
QTreeWidgetItem* displayEntityItem = myLineToStateViewMap[nonConstStateView];
if(displayEntityItem)
{
myUi.myEntityTree->takeTopLevelItem(
myUi.myEntityTree->indexOfTopLevelItem(displayEntityItem));
myLineToStateViewMap[nonConstStateView] = 0;
}
}
void DtEntityList::slot_onObjectUpdated(makVrv::DtStateView<makVrv::DtVrlinkSimulatedEntityState>* entityState)
{
//If the marking text is has not updated, this entity is not ready to be updated.
//The VR-Forces front end does not have a concept of discovery criteria so we must
//simulate the criteria in this way.
if(entityState->state().myMarkingText.empty() ||
!DtVrfStateViewCollectionManager::instance(myDe).objectUUID(entityState->id()).isValid())
{
//If marking text is empty then force an update of the state view until marking text is filled in
entityState->forceUpdate();
return;
}
QTreeWidgetItem* displayEntityItem = myLineToStateViewMap[entityState];
if(displayEntityItem)
{
if(displayEntityItem->text(0).isEmpty())
{
DtVrfCurrentTaskManager::instance(myDe).requestCurrentTasksFor(entityState->id(),
boost::bind(&DtEntityList::slot_onCurrentTaskChanged, this, _1));
//In order to get the task of an object we need to subscribe to the task manager
//Note that we do this here instead of when the object is added because the
//DtVrfCurrentTaskManager will not work until after an update has
//identified the object name.
DtVrfCurrentTaskManager& manager = DtVrfCurrentTaskManager::instance(DtPage::myDe);
manager.subscribeForTaskInformation(entityState->id());
}
if(displayEntityItem->text(0).toLatin1().constData() != entityState->state().myMarkingText)
{
displayEntityItem->setText(0,entityState->state().myMarkingText.c_str());
}
//Get the icon for this item. If the serial numbers are different, then set the icon
bool destroyed = false;
makVrf::DtEntityMapperKey key(entityState->state().myForce, entityState->state().myEntityType.c_str());
if (key.kind() == 11)
{
destroyed = (entityState->state().myAppearance == DtDamageDestroyed);
}
else
{
DtAppearance app(DtEntityType(entityState->state().myEntityType.c_str()));
app.setAppearance(entityState->state().myAppearance);
destroyed = (app.damageState() == DtDamageDestroyed);
}
QPixmap pMap = makVrf::DtVrfGuiSymbolMapper::instance(DtPage::myDe).getIcon(
key, destroyed, 48, false, &entityState->state());
if (pMap.cacheKey() != displayEntityItem->icon(0).cacheKey())
{
displayEntityItem->setIcon(0, pMap);
}
}
}
void DtEntityList::slot_onCurrentTaskChanged(DtUUID entityName)
{
if(!entityName.isValid()) return;
const_cast<makVrv::DtStateView<makVrv::DtVrlinkSimulatedEntityState>*>(mySimulatedEntityStateView->findStateView(
DtVrfStateViewCollectionManager::instance(myDe).lookupIdByUUID(entityName)));
if (!entityState)
{
return;
}
QTreeWidgetItem* displayEntityItem = myLineToStateViewMap[entityState];
if(displayEntityItem)
{
//Use the task manager to grab the current task and display it.
DtVrfCurrentTaskManager& manager = DtVrfCurrentTaskManager::instance(DtPage::myDe);
const DtVrfCurrentTaskManager::EntityTaskInformation* allTasks = manager.tasksFor(entityState->id());
if (allTasks)
{
if(allTasks->size() == 0)
{
//No task
displayEntityItem->setText(1,"");
displayEntityItem->setText(2,"");
}
else
{
DtSimTaskMessageType taskType = ((*allTasks)[0]).task->type();
displayEntityItem->setText(1,QString::fromUtf8(taskType.type().c_str()));
fillDestinationLine(((*allTasks)[0]).task.get(),displayEntityItem);
}
}
}
}
void DtEntityList::fillDestinationLine(DtSimTask* task,QTreeWidgetItem* displayEntityItem)
{
DtSimTaskMessageType taskType = task->type();
if ((taskType == DtMoveToLocationTaskType) || (taskType == DtSimTaskMessageType("move-to-location-path-plan")))
{
//For location destinations, just display the ending point.
DtMoveToLocationTask* locTask = dynamic_cast<DtMoveToLocationTask*>(task);
if (locTask)
{
displayEntityItem->setText(2, QString::fromUtf8(formatSourceToDisplay(locTask->aimingPoint()).c_str()));
}
else
{
DtScriptedTaskTask* stt = dynamic_cast<DtScriptedTaskTask*>(task);
if (stt)
{
DtRwVector* rwv = dynamic_cast<DtRwVector*>(stt->variables().findVariableBinding("destination"));
if (rwv)
{
displayEntityItem->setText(2, QString::fromUtf8(formatSourceToDisplay(*rwv).c_str()));
}
}
}
}
else if ((taskType == DtMoveToTaskType) || (taskType == DtSimTaskMessageType("move-to-waypoint-path-plan")))
{
DtUUID controlPoint(DtUUID::nullUUID());
//For location destinations, display the ending point and the name of the waypoint.
DtMoveToTask* locTask = dynamic_cast<DtMoveToTask*>(task);
if (locTask)
{
controlPoint = locTask->controlPoint();
}
else
{
DtScriptedTaskTask* stt = dynamic_cast<DtScriptedTaskTask*>(task);
if (stt)
{
DtRwUUID* cp = dynamic_cast<DtRwUUID*>(stt->variables().findVariableBinding("destination"));
if (cp)
{
controlPoint = *cp;
}
}
}
if (!controlPoint.isValid())
{
return;
}
makVrv::DtStateView<makVrv::DtVrlinkSimulatedBaseState>* sv = DtVrfStateViewCollectionManager::instance(myDe).findStateView(controlPoint);
if (sv)
{
if (ep)
{
//Found the named waypoint
QString destinationText =
QString::fromUtf8(formatSourceToDisplay(ep->myPoints[0])) + " (" + QString::fromUtf8(controlPoint.markingText()) + ")";
displayEntityItem->setText(2,destinationText);
}
}
}
}
}

Document ID: Generated on Fri Apr 26 21:53:14 EDT 2019 from SVN revision 197883
Copyright © 2005-2019 VT MAK. All Rights Reserved (www.mak.com)