From 448aa97ce6fe99c109add250d3b819677cc04230 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Wed, 17 Sep 2014 01:11:39 +0200 Subject: [PATCH] Removed old GUI application and added new version --- CMakeLists.txt | 2 + gui/CMakeLists.txt | 7 +- gui/luascriptexternalcontrol/CMakeLists.txt | 22 ++++ gui/luascriptexternalcontrol/main.cpp | 35 +++++++ gui/luascriptexternalcontrol/mainwindow.cpp | 103 ++++++++++++++++++ gui/luascriptexternalcontrol/mainwindow.h | 67 ++++++++++++ gui/src/CMakeLists.txt | 20 ---- gui/src/main.cpp | 12 --- gui/src/mainwindow.cpp | 109 -------------------- gui/src/mainwindow.h | 33 ------ gui/src/mainwindow.ui | 102 ------------------ 11 files changed, 230 insertions(+), 282 deletions(-) create mode 100644 gui/luascriptexternalcontrol/CMakeLists.txt create mode 100644 gui/luascriptexternalcontrol/main.cpp create mode 100644 gui/luascriptexternalcontrol/mainwindow.cpp create mode 100644 gui/luascriptexternalcontrol/mainwindow.h delete mode 100644 gui/src/CMakeLists.txt delete mode 100644 gui/src/main.cpp delete mode 100644 gui/src/mainwindow.cpp delete mode 100644 gui/src/mainwindow.h delete mode 100644 gui/src/mainwindow.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index 3bb7d3ed56..2b247e5159 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,3 +122,5 @@ endif () ######################################################################################### add_subdirectory(src) + +add_subdirectory(gui) \ No newline at end of file diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index 7feae25029..e33b8eb266 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -1,8 +1,3 @@ cmake_minimum_required(VERSION 2.8.11) -project(GUI) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${GUI_SOURCE_DIR}/build-debug) - -set(CMAKE_BUILD_TYPE Debug) - -add_subdirectory(src) \ No newline at end of file +add_subdirectory(luascriptexternalcontrol) \ No newline at end of file diff --git a/gui/luascriptexternalcontrol/CMakeLists.txt b/gui/luascriptexternalcontrol/CMakeLists.txt new file mode 100644 index 0000000000..44d82b517d --- /dev/null +++ b/gui/luascriptexternalcontrol/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 2.8.11) + +project(LuascriptExternalControl) +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +#set(QT_PATH_OPTION "C:/Qt/5.1.0/5.1.0/msvc2012_64_opengl/lib" CACHE PATH "Path to Qt folder") +#set(QT_PATH_OPTION "C:\\Qt\\Qt5\\5.3\\msvc2013_64_opengl\\lib\\cmake\\Qt5Widgets") +#option(QT_PATH_OPTION "Path to the Qt5 folder" "C:/Qt/5.1.0/5.1.0/msvc2012_64_opengl/lib") +#message("Option: ${QT_PATH_OPTION}") + +#set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH} ${QT_PATH_OPTION}") + +#set(CMAKE_PREFIX_PATH $ENV{QTDIR}) + +#message("Prefix: ${CMAKE_PREFIX_PATH}") + +set(CMAKE_AUTOMOC ON) +find_package(Qt5Widgets) +find_package(Qt5Network) +add_executable(LuascriptExternalControl WIN32 main.cpp mainwindow.cpp) +#qt5_use_modules(LuascriptExternalControl, Widgets) +target_link_libraries(LuascriptExternalControl Qt5::Widgets Qt5::Network) \ No newline at end of file diff --git a/gui/luascriptexternalcontrol/main.cpp b/gui/luascriptexternalcontrol/main.cpp new file mode 100644 index 0000000000..59eb5baf55 --- /dev/null +++ b/gui/luascriptexternalcontrol/main.cpp @@ -0,0 +1,35 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include +#include "mainwindow.h" + +int main(int argc, char** argv) { + QApplication app(argc, argv); + + MainWidget window; + window.show(); + + return app.exec(); +} diff --git a/gui/luascriptexternalcontrol/mainwindow.cpp b/gui/luascriptexternalcontrol/mainwindow.cpp new file mode 100644 index 0000000000..31fb8b31da --- /dev/null +++ b/gui/luascriptexternalcontrol/mainwindow.cpp @@ -0,0 +1,103 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include "mainwindow.h" + +#include +#include +#include + +MainWidget::MainWidget() + : _ipAddress(new QLineEdit) + , _command(new QLineEdit) + , _logWindow(new QTextEdit) + , _socket(nullptr) +{ + setWindowTitle("OpenSpace LuaScripting GUI"); + + QGridLayout* layout = new QGridLayout; + _ipAddress->setMinimumWidth(200); + _ipAddress->setText("127.0.0.1"); + layout->addWidget(_ipAddress, 0, 0); + + QPushButton* connectButton = new QPushButton("Connect"); + connect(connectButton, SIGNAL(clicked()), this, SLOT(onConnectButton())); + connectButton->show(); + layout->addWidget(connectButton, 0, 1); + + _command->setMinimumWidth(200); + layout->addWidget(_command, 1, 0); + + QPushButton* sendButton = new QPushButton("Send"); + sendButton->setDefault(true); + connect(sendButton, SIGNAL(clicked()), this, SLOT(sendCommandButton())); + layout->addWidget(sendButton, 1, 1); + + layout->addWidget(_logWindow, 2, 0, 1, 2); + + setLayout(layout); +} + +MainWidget::~MainWidget() { + delete _command; + delete _socket; +} + +void MainWidget::readTcpData() { + QByteArray data = _socket->readAll(); + + if (_logWindow->toPlainText().isEmpty()) + _logWindow->setText(data.data()); + else + _logWindow->setText(_logWindow->toPlainText() + "\n" + data.data()); +} + +void MainWidget::onConnectButton() { + delete _socket; + + _socket = new QTcpSocket(this); + connect( _socket, SIGNAL(readyRead()), SLOT(readTcpData()) ); + _socket->connectToHost(_ipAddress->text(), 20500); + +} + +void MainWidget::sendCommandButton() { + if (!_socket) { + if (_logWindow->toPlainText().isEmpty()) + _logWindow->setText("No connection found"); + else + _logWindow->setText(_logWindow->toPlainText() + "\n" + "No connection found"); + return; + } + + QString command = _command->text(); + + if (_logWindow->toPlainText().isEmpty()) + _logWindow->setText(command); + else + _logWindow->setText(_logWindow->toPlainText() + "\n" + command); + + + _socket->write(("0" + command + "\r\n").toLatin1()); +} diff --git a/gui/luascriptexternalcontrol/mainwindow.h b/gui/luascriptexternalcontrol/mainwindow.h new file mode 100644 index 0000000000..46f3a5892d --- /dev/null +++ b/gui/luascriptexternalcontrol/mainwindow.h @@ -0,0 +1,67 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __MAINWINDOW_H__ +#define __MAINWINDOW_H__ + +#include +#include +#include +#include + +class MainWidget : public QWidget { +Q_OBJECT +public: + MainWidget(); + ~MainWidget(); + +private slots: + void onConnectButton(); + void sendCommandButton(); + void readTcpData(); + +private: + QLineEdit* _ipAddress; + QLineEdit* _command; + QTextEdit* _logWindow; + + QTcpSocket* _socket; + + +// +//private slots: +// void on__connectButton_clicked(); +// void on__statsCheckBox_toggled(bool checked); +// void readTcpData(); +// void on__graphCheckBox_toggled(bool checked); +// void on__renderComboBox_currentIndexChanged(const QString &arg1); +// +//private: +// qint64 sendToSGCT(QByteArray data); +// +// Ui::MainWindow *ui; +// QTcpSocket* _sgctSocket; +}; + +#endif // __MAINWINDOW_H__ diff --git a/gui/src/CMakeLists.txt b/gui/src/CMakeLists.txt deleted file mode 100644 index d145273478..0000000000 --- a/gui/src/CMakeLists.txt +++ /dev/null @@ -1,20 +0,0 @@ -# FIXME: ugly hack for linking qt5 -set (CMAKE_PREFIX_PATH "/home/hhellteg/Qt/5.2.1/gcc_64") - -# Find includes in corresponding build directories -set(CMAKE_INCLUDE_CURRENT_DIR ON) -# Instruct CMake to run moc automatically when needed. -set(CMAKE_AUTOMOC ON) - -# Find the Qt libraries -find_package(Qt5Widgets) -find_package(Qt5Network) - -# Create ui_mainwindow.h file -qt5_wrap_ui(QT_UI_HEADERS mainwindow.ui) - -# Tell CMake to create the executable -add_executable(gui main.cpp mainwindow.cpp ${QT_UI_HEADERS}) - -# Use the needed modules from Qt 5. -target_link_libraries(gui Qt5::Widgets Qt5::Network) \ No newline at end of file diff --git a/gui/src/main.cpp b/gui/src/main.cpp deleted file mode 100644 index 1797005f1d..0000000000 --- a/gui/src/main.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "mainwindow.h" -#include -#include - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - MainWindow w; - w.show(); - - return a.exec(); -} diff --git a/gui/src/mainwindow.cpp b/gui/src/mainwindow.cpp deleted file mode 100644 index 39bc8b0eb4..0000000000 --- a/gui/src/mainwindow.cpp +++ /dev/null @@ -1,109 +0,0 @@ -#include "mainwindow.h" -#include "ui_mainwindow.h" - -#include - -#include -#include -#include -#include - -MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::MainWindow), - _sgctSocket(NULL) { - ui->setupUi(this); - ui->_hostEdit->setText("127.0.0.1"); - setWindowTitle("OpenSpace Qt GUI"); - ui->_statsCheckBox->setEnabled(false); - ui->_graphCheckBox->setEnabled(false); - ui->_renderComboBox->setEnabled(false); - -// TEST JSON -// QJsonObject json, jsonObj2; -// QJsonArray jsonArr, jsonArr2; -// json["Value 1"] = (QString("Herp")); -// json["Value 2"] = (QString("Derp")); -// jsonArr.push_back(QString("val1")); -// jsonArr.push_back(QString("val2")); -// jsonArr.push_back(QString("val3")); -// jsonArr.push_back(QString("val4")); -// jsonArr.push_back(QString("val5")); -// jsonArr2.push_back(QString("val21")); -// jsonArr2.push_back(QString("val22")); -// jsonArr2.push_back(QString("val23")); -// jsonArr2.push_back(QString("val24")); -// jsonArr2.push_back(QString("val25")); -// jsonObj2["ArrayYo2"] = jsonArr2; -// jsonArr.push_back(jsonObj2); -// json["ArrayYo"] = jsonArr; -// QJsonDocument doc; -// doc.setObject(json); -// std::cout << doc.toJson().data() << std::endl; -// quick_exit(0); -} - -MainWindow::~MainWindow() { - delete ui; -} - -void MainWindow::on__connectButton_clicked() { - _sgctSocket = new QTcpSocket(this); - connect( _sgctSocket, SIGNAL(readyRead()), SLOT(readTcpData()) ); - _sgctSocket->connectToHost(ui->_hostEdit->text(), 20500); - if (_sgctSocket->waitForConnected()) { - ui->_statsCheckBox->setEnabled(true); - ui->_graphCheckBox->setEnabled(true); - ui->_renderComboBox->setEnabled(true); - } else { - std::cout << "Connection failed" << std::endl; - ui->_statsCheckBox->setEnabled(false); - ui->_graphCheckBox->setEnabled(false); - ui->_renderComboBox->setEnabled(false); - } -} - -void MainWindow::on__statsCheckBox_toggled(bool checked) { - QJsonObject json; - QJsonDocument doc; - if (checked) { - json["stats"] = 1; - } else { - json["stats"] = 0; - } - doc.setObject(json); - std::cout << "Bytes sent: " << sendToSGCT(doc.toJson()) << " " << std::flush; -} - -void MainWindow::on__graphCheckBox_toggled(bool checked) { - QJsonObject json; - QJsonDocument doc; - if (checked) { - json["graph"] = 1; - } else { - json["graph"] = 0; - } - doc.setObject(json); - std::cout << "Bytes sent: " << sendToSGCT(doc.toJson()) << " " << std::flush; -} - -void MainWindow::readTcpData() { - QByteArray data = _sgctSocket->readAll(); - std::cout << data.data() << std::flush; -} - -void MainWindow::on__renderComboBox_currentIndexChanged(const QString &arg1){ - QJsonObject json; - QJsonDocument doc; - if (arg1.compare(QString("VolumeRaycaster")) == 0) { - json["renderer"] = QString("volumeraycaster"); - } else if (arg1.compare(QString("Flare")) == 0) { - json["renderer"] = QString("flare"); - } - doc.setObject(json); - std::cout << "Bytes sent: " << sendToSGCT(doc.toJson()) << " " << std::flush; -} - -qint64 MainWindow::sendToSGCT(QByteArray data) { - return _sgctSocket->write(data + "\r\n"); // "\r\n" seperates messages -} diff --git a/gui/src/mainwindow.h b/gui/src/mainwindow.h deleted file mode 100644 index c392d03b48..0000000000 --- a/gui/src/mainwindow.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include -#include - -namespace Ui { -class MainWindow; -} - -class MainWindow : public QMainWindow -{ - Q_OBJECT - -public: - explicit MainWindow(QWidget *parent = 0); - ~MainWindow(); - -private slots: - void on__connectButton_clicked(); - void on__statsCheckBox_toggled(bool checked); - void readTcpData(); - void on__graphCheckBox_toggled(bool checked); - void on__renderComboBox_currentIndexChanged(const QString &arg1); - -private: - qint64 sendToSGCT(QByteArray data); - - Ui::MainWindow *ui; - QTcpSocket* _sgctSocket; -}; - -#endif // MAINWINDOW_H diff --git a/gui/src/mainwindow.ui b/gui/src/mainwindow.ui deleted file mode 100644 index 986a7eb747..0000000000 --- a/gui/src/mainwindow.ui +++ /dev/null @@ -1,102 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 303 - 312 - - - - MainWindow - - - - - - - Graph - - - - - - - - VolumeRaycaster - - - - - Flare - - - - - - - - Connect - - - - - - - Stats - - - - - - - Debug info - - - - - - - Renderer - - - - - - - - - - Host - - - - - - - - - 0 - 0 - 303 - 20 - - - - - - TopToolBarArea - - - false - - - - - - - -