![]() |
VR-Forces 4.0.4 Class Documentation
|
/****************************************************************************** ** Copyright (c) 2012 MAK Technologies, Inc. ** All rights reserved. ******************************************************************************/ /****************************************************************************** ** $RCSfile: remoteControlConsole.h,v $ $Revision: 1.2 $ $State: Exp $ ******************************************************************************/ //\file remoteControlConsole.h #pragma once #include <vrvUtil/signalslib.h> #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; class DtRemoteControlCommand; class DtRemoteControlConsole : public QDialog { Q_OBJECT public: DtRemoteControlConsole(makVrv::DtDe& de, QWidget* parent); virtual ~DtRemoteControlConsole(); 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); protected: makVrv::DtDe& myDe; QVBoxLayout* myMainLayout; QTextEdit* myConsole; //The output of the command QLineEdit* myCommand; //Command input typedef std::vector<DtRemoteControlCommand*> Commands; Commands myCommands; };
remoteControlConsole.cxx
/****************************************************************************** ** Copyright (c) 2012 MAK Technologies, Inc. ** All rights reserved. ******************************************************************************/ /****************************************************************************** ** $RCSfile: remoteControlConsole.cxx,v $ $Revision: 1.2 $ $State: Exp $ ******************************************************************************/ //\file remoteControlConsole.cxx #include "remoteControlConsole.h" #include "remoteControlCommands.h" #include <vrvCore/DtDe.h> #include <vrfGuiCore/DtGuiThreadVrfRemoteController.h> #include <vrfGuiCore/DtVrfSelectionHandler.h> #include <QtGui/QTextEdit> #include <QtGui/QLineEdit> #include <QtGui/QLayout> #include <QtGui/QLabel> using namespace makVrv; using namespace makVrf; DtRemoteControlConsole::DtRemoteControlConsole(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); 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")); addCommand(DtRemoteControlCreateCommand()); addCommand(DtRemoteControlLoadScenarioCommand()); addCommand(DtRemoteControlNewScenarioCommand()); addCommand(DtRemoteControlRewindScenarioCommand()); addCommand(DtRemoteControlPlayScenarioCommand()); addCommand(DtRemoteControlPauseScenarioCommand()); addCommand(DtRemoteControlSaveScenarioCommand()); 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)); } DtRemoteControlConsole::~DtRemoteControlConsole() { DtVrfSelectionHandler::instance(myDe).signal_lastDatabaseLocationSet.disconnect(boost::bind(&DtRemoteControlConsole::slot_onDatabaseLocationSet, this, _1)); Commands::iterator iter = myCommands.begin(); while (iter != myCommands.end()) { DtRemoteControlCommand* c = *iter; delete c; ++iter; } myCommands.clear(); } void DtRemoteControlConsole::addCommand(const DtRemoteControlCommand& c) { myCommands.push_back(c.clone()); } void DtRemoteControlConsole::print(const QString& c) { myConsole->insertPlainText(c + "\r\n"); } void DtRemoteControlConsole::help() { Commands::const_iterator iter = myCommands.begin(); while (iter != myCommands.end()) { print((*iter)->help()); ++iter; } } void DtRemoteControlConsole::executeCommand(const QString& c) { 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(); } void DtRemoteControlConsole::slot_onCommandComplete(const QString& c, DtRemoteControlCommand* command) { command->signal_commandComplete.disconnect(boost::bind(&DtRemoteControlConsole::slot_onCommandComplete, this, _1, _2)); print(c); } void DtRemoteControlConsole::processCommand() { executeCommand(myCommand->text()); } void DtRemoteControlConsole::slot_onDatabaseLocationSet(const DtVector& v) { QString point; point.sprintf("%f,%f,%f", v.x(), v.y(), v.z()); myCommand->setText(myCommand->text() + " " + point); }