VR-Forces Development_Version Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages

remoteControlCommands.h

/******************************************************************************
** Copyright (c) 2015 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
//\file remoteControlCommands.h
#pragma once
#include <vlpi/entityType.h>
#include <QtCore/QStringList>
namespace makVrv
{
class DtDe;
}
class QString;
class DtEntityIdentifier;
class DtUUID;
//These classes will represent commands that can be executed by using the
//DtVrossThreadVrfRemoteControl class.
{
public:
virtual bool execute(makVrv::DtDe&, const QString& command) = 0;
virtual DtRemoteControlCommand* clone() const = 0;
QString help() const
{
return myHelp;
}
QString command() const
{
return myCommand;
}
boost::signal<void (const QString&, DtRemoteControlCommand*)> signal_commandComplete;
protected:
//Parse out the string. All tokens are separated by spaces or enclosed in quotes or
//parens
virtual QStringList tokenize(const QString&, char delim = ' ') const;
//Parses a point of the form x,y,z
bool parsePoint(const QString&, DtVector&) const;
protected:
DtRemoteControlCommand(const QString& command, const QString& help);
protected:
QString myCommand;
QString myHelp;
};
//This command will create a single point object (entity, waypoint, aggregate) and will notify the user
//when the command has been completed
{
public:
virtual bool execute(makVrv::DtDe&, const QString& command);
virtual DtRemoteControlCommand* clone() const;
//Convert string to entity type either by name or by actual type
DtEntityType entityToCreate(const QString& c, makVrv::DtDe& de) const;
//Returns the currently selected simulation address
DtSimulationAddress simulationAddress(makVrv::DtDe&) const;
protected:
//Called when the object is created, will signal complete with the name and the object id
void objectCreated(DtString, const DtUUID&, const DtEntityIdentifier&, const DtObjectType&);
};
//Loads the specified scenario into the simulation
{
public:
virtual bool execute(makVrv::DtDe&, const QString& command);
virtual DtRemoteControlCommand* clone() const;
};
//Loads a new scenario into the system
{
public:
virtual bool execute(makVrv::DtDe&, const QString& command);
virtual DtRemoteControlCommand* clone() const;
};
//Rewinds the current scenario
{
public:
virtual bool execute(makVrv::DtDe&, const QString& command);
virtual DtRemoteControlCommand* clone() const;
};
//Pauses the current scenario
{
public:
virtual bool execute(makVrv::DtDe&, const QString& command);
virtual DtRemoteControlCommand* clone() const;
};
//Plays the current scenario
{
public:
virtual bool execute(makVrv::DtDe&, const QString& command);
virtual DtRemoteControlCommand* clone() const;
};
//Saves the current scenario
{
public:
virtual bool execute(makVrv::DtDe&, const QString& command);
virtual DtRemoteControlCommand* clone() const;
};

remoteControlCommands.cxx

/******************************************************************************
** Copyright (c) 2015 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
//\file remoteControlCommands.cxx
#include <vrvCore/DtDe.h>
#include <QtCore/QString>
#include <QtCore/QObject>
using namespace makVrf;
using namespace makVrv;
DtRemoteControlCommand::DtRemoteControlCommand(const QString& command, const QString& help)
: myCommand(command)
, myHelp(help)
{
}
: myCommand(orig.myCommand)
, myHelp(orig.myHelp)
{
}
bool DtRemoteControlCommand::parsePoint(const QString& c, DtVector& v) const
{
QStringList vals = c.split(',');
if (vals.size() != 3)
{
return false;
}
v.setX(atof(vals[0].trimmed().toLatin1().constData()));
v.setY(atof(vals[1].trimmed().toLatin1().constData()));
v.setZ(atof(vals[2].trimmed().toLatin1().constData()));
return true;
}
QStringList DtRemoteControlCommand::tokenize(const QString& c, char delim) const
{
int iLimit = c.length();
int i;
QString token;
QStringList tokens;
bool inQuote = false;
int inParen = 0;
for (i = 0; i < iLimit; i++)
{
if (c[i] == '"')
{
if (inParen == 0)
{
if (!inQuote)
{
inQuote = true;
}
else
{
if (token.length())
{
tokens += token;
}
token = "";
inQuote = false;
}
}
}
else if (c[i] == '(')
{
if (!inQuote)
{
inParen++;
}
}
else if (c[i] == ')')
{
if (!inQuote)
{
inParen--;
if (inParen == 0)
{
if (token.length())
{
tokens += token;
}
token = "";
}
}
}
else if (c[i] == delim)
{
if (!inQuote && (inParen == 0))
{
if (token.length())
{
tokens += token;
}
token = "";
}
else
{
token += c[i];
}
}
else
{
token += c[i];
}
}
if (token.length())
{
tokens += token;
}
return tokens;
}
//************************************** Create command
: DtRemoteControlCommand("create", QObject::tr("create <object name|entity type - delimited by comma (e.g. 1,1,225,1,1,3,0)> <force number> <x,y,z> [simulation address]"))
{
}
{
}
DtEntityType DtRemoteControlCreateCommand::entityToCreate(const QString& c, DtDe& de) const
{
QStringList vals = c.split(',');
DtEntityType type;
if (vals.size() == 7)
{
type = DtEntityType(c.toLatin1().constData());
}
else
{
type = DtCreateMenu::instance(de).nameToType(c);
}
return type;
}
{
return DtGuiThreadVrfRemoteController::instance(de).backendManager().selectedBackend();
}
bool DtRemoteControlCreateCommand::execute(makVrv::DtDe& de, const QString& command)
{
QStringList tokens = tokenize(command);
int iLimit = tokens.size();
if (iLimit < 4)
{
return false;
}
DtEntityType type = entityToCreate(tokens[1], de);
if (type == DtEntityType())
{
QString error = QObject::tr("Cannot create entity of type ") + tokens[1];
signal_commandComplete(error, this);
return false;
}
int force = atoi(tokens[2].toLatin1().constData());
DtVector point;
if (!parsePoint(tokens[3], point))
{
QString error = QObject::tr("Location format is incorrect ") + tokens[2];
signal_commandComplete(error, this);
return false;
}
DtSimulationAddress simAddress;
if (iLimit == 5)
{
simAddress = DtSimulationAddress(tokens[5].toLatin1().constData());
}
else
{
simAddress = simulationAddress(de);
}
//Check to see if the specified backend can simulate. If not then abort
if (!DtGuiThreadVrfRemoteController::instance(de).backendManager().backendCanSimulate(simAddress))
{
signal_commandComplete(QObject::tr("Backend specified is not ready to simulate: ") + simAddress.string(), this);
return false;
}
DtVector position;
de.sharedState().coordinateSystem().localToNetPos( point, position );
//Convert the local position to a geocentric position
//Create the entity and print out the name and entity id
//This is where the remote controller is used to create the entity object
DtGuiThreadVrfRemoteController::instance(de).createEntity(boost::bind(&DtRemoteControlCreateCommand::objectCreated, this, _1, _2, _3, _4),
simAddress, type, position, (DtForceType)force, 0.0, "", "");
return true;
}
void DtRemoteControlCreateCommand::objectCreated(DtString s, const DtUUID&, const DtEntityIdentifier& id, const DtObjectType&)
{
QString message = QObject::tr("Object ") + s.c_str();
message += QObject::tr(" with id ") + id.string();
message += QObject::tr(" has been created.");
signal_commandComplete(message, this);
}
{
}
//************************ Load Scenario Command
: DtRemoteControlCommand("load", QObject::tr("load <scenario name>"))
{
}
{
}
{
QStringList tokens = tokenize(command);
if (tokens.size() != 2)
{
return false;
}
// If this is not a relative or abs path, then, add the scenarios directory
DtFilename fn(tokens[1].toLatin1().constData());
if (fn.extension() != "scn")
{
fn += ".scn";
}
if (!fn.exists())
{
fn = DtFilename::combine("../userData/scenarios", fn);
}
if (!DtGuiThreadVrfRemoteController::instance(de).loadScenario(fn.c_str()))
{
signal_commandComplete(QObject::tr("Could not load scenario file ") + tokens[1], this);
return false;
}
signal_commandComplete(QObject::tr("Loading scenario ") + tokens[1], this);
return true;
}
{
}
//************************ New Scenario Command
: DtRemoteControlCommand("new", QObject::tr("new <terrain database>"))
{
}
{
}
{
QStringList tokens = tokenize(command);
if (tokens.size() != 2)
{
return false;
}
DtFilename terrain(tokens[1].toLatin1().constData());
if (!terrain.extension().length())
{
terrain += ".mtf";
}
DtGuiThreadVrfRemoteController::instance(de).newScenario(terrain);
signal_commandComplete(QObject::tr("Creating new scenario ") + terrain.c_str(), this);
return true;
}
{
}
//************************ Save Scenario Command
: DtRemoteControlCommand("save", QObject::tr("save <scenario name>"))
{
}
{
}
{
QStringList tokens = tokenize(command);
if (tokens.size() != 2)
{
return false;
}
//The scenario handler will call down to the cross thread remote controller's save scenario method, however,
//always use this method to save the current scenario as the handler will fill in all the relevant scenario
//information.
DtFilename fp(tokens[1].toLatin1().constData());
DtFilename scenario(fp);
fp.stripPath();
if (fp == scenario)
{
std::string ud = de.dePathConfiguration().userPath() + "/scenarios/";
ud += scenario.c_str();
scenario = ud.c_str();
}
DtVrfSaveScenarioHandler::instance(de).saveScenario(scenario.c_str(), true);
signal_commandComplete(QObject::tr("Saving scenario ") + tokens[1], this);
return true;
}
{
}
//************************ Rewind Scenario Command
: DtRemoteControlCommand("rewind", QObject::tr("rewind"))
{
}
{
}
{
QStringList tokens = tokenize(command);
if (tokens.size() != 1)
{
return false;
}
DtGuiThreadVrfRemoteController::instance(de).rewindScenario();
signal_commandComplete(QObject::tr("Scenario Rewound"), this);
return true;
}
{
}
//************************ Play Scenario Command
: DtRemoteControlCommand("run", QObject::tr("run"))
{
}
{
}
{
QStringList tokens = tokenize(command);
if (tokens.size() != 1)
{
return false;
}
DtGuiThreadVrfRemoteController::instance(de).runScenario();
signal_commandComplete(QObject::tr("Scenario Playing"), this);
return true;
}
{
}
//************************ Pause Scenario Command
: DtRemoteControlCommand("pause", QObject::tr("pause"))
{
}
{
}
{
QStringList tokens = tokenize(command);
if (tokens.size() != 1)
{
return false;
}
DtGuiThreadVrfRemoteController::instance(de).pauseScenario();
signal_commandComplete(QObject::tr("Scenario Paused"), this);
return true;
}
{
}

Document ID: Generated on Tue Mar 8 22:13:38 EST 2016 from SVN revision 162938
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)