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

remoteControlConsole.h

/******************************************************************************
** Copyright (c) 2012 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
/******************************************************************************
** $RCSfile: remoteControlConsole.h,v $ $Revision: 1.2 $ $State: Exp $
******************************************************************************/
//\file remoteControlConsole.h
#pragma once
#include <QtGui/QDialog>
namespace makVrv
{
class DtDe;
}
// The DtRemoteControlConsole class will allow the user to type in remote control console commands
// to manipulate the simulation. For a list of commands, type "help" at the command prompt
class DtVector;
class QVBoxLayout;
class QTextEdit;
class QLineEdit;
{
Q_OBJECT
public:
protected:
virtual void addCommand(const DtRemoteControlCommand&);
//Prints a line of text to the console window. Will add CR/LF
virtual void print(const QString&);
//Prints out all help for all commands
virtual void help();
//Called when a command is complete, prints out command complete string
virtual void slot_onCommandComplete(const QString&, DtRemoteControlCommand*);
//Called when the user clicks on the map to set the database location. Simply adds the point to the current command line
virtual void slot_onDatabaseLocationSet(const DtVector&);
protected slots:
//Called when return is pressed in the command widget. Processes the command
virtual void processCommand();
//Parse and execute the supplied command. Command will be the first item before the
//space
virtual void executeCommand(const QString& command);
public:
QVBoxLayout* myMainLayout;
QTextEdit* myConsole; //The output of the command
QLineEdit* myCommand; //Command input
protected:
typedef std::vector<DtRemoteControlCommand*> Commands;
};

remoteControlConsole.cxx

/******************************************************************************
** Copyright (c) 2012 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
/******************************************************************************
** $RCSfile: remoteControlConsole.cxx,v $ $Revision: 1.2 $ $State: Exp $
******************************************************************************/
//\file remoteControlConsole.cxx
#include <vrvCore/DtDe.h>
#include <QtGui/QTextEdit>
#include <QtGui/QLineEdit>
#include <QtGui/QLayout>
#include <QtGui/QLabel>
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);
QLabel* label = new QLabel(tr("Console"), this);
myMainLayout->addWidget(label);
myConsole = new QTextEdit(this);
myConsole->setReadOnly(true);
myMainLayout->addWidget(myConsole);
label = new QLabel(tr("Command"), this);
myCommand = new QLineEdit(this);
myMainLayout->addWidget(label);
myMainLayout->addWidget(myCommand);
connect(myCommand, SIGNAL(returnPressed()), this, SLOT(processCommand()));
setWindowTitle(tr("Remote Control Console"));
myCommand->setFocus();
resize(500, 400);
//Connect to database changed signal so user can click and place information in dialog
DtVrfSelectionHandler::instance(myDe).signal_lastDatabaseLocationSet.connect(boost::bind(&DtRemoteControlConsole::slot_onDatabaseLocationSet, this, _1));
}
{
DtVrfSelectionHandler::instance(myDe).signal_lastDatabaseLocationSet.disconnect(boost::bind(&DtRemoteControlConsole::slot_onDatabaseLocationSet, this, _1));
Commands::iterator iter = myCommands.begin();
while (iter != myCommands.end())
{
delete c;
++iter;
}
myCommands.clear();
}
{
myCommands.push_back(c.clone());
}
void DtRemoteControlConsole::print(const QString& c)
{
myConsole->insertPlainText(c + "\r\n");
}
{
Commands::const_iterator iter = myCommands.begin();
while (iter != myCommands.end())
{
print((*iter)->help());
++iter;
}
}
{
QStringList l = c.split(" ");
if (!l.count())
{
return;
}
if (l[0].toLower() == "help")
{
help();
myCommand->setText("");
return;
}
else
{
Commands::const_iterator iter = myCommands.begin();
while (iter != myCommands.end())
{
if ((*iter)->command().toLower() == l[0])
{
(*iter)->signal_commandComplete.connect(boost::bind(&DtRemoteControlConsole::slot_onCommandComplete, this, _1, _2));
if ((*iter)->execute(myDe, myCommand->text()))
{
myCommand->setText("");
}
return;
}
++iter;
}
}
print(tr("Command not recognized. Valid commands:\n"));
help();
}
{
print(c);
}
{
}
{
QString point;
point.sprintf("%f,%f,%f", v.x(), v.y(), v.z());
myCommand->setText(myCommand->text() + " " + point);
}

Document ID: Generated on Wed Jul 29 00:55:00 EDT 2015 from SVN revision 155257
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)