--- a/nbproject/configurations.xml Thu Mar 14 00:23:34 2019 +0100
+++ b/nbproject/configurations.xml Thu Mar 14 16:11:08 2019 +0100
@@ -58,6 +58,8 @@
</df>
</df>
<df name="src">
+ <in>SimulatorSocketServer.cpp</in>
+ <in>SimulatorSocketServer.h</in>
<in>SimulatorWindow.cpp</in>
<in>SimulatorWindow.h</in>
<in>spacenav-simulator-qt.cpp</in>
@@ -144,6 +146,10 @@
</incDir>
</ccTool>
</folder>
+ <item path="src/SimulatorSocketServer.cpp" ex="false" tool="1" flavor2="0">
+ </item>
+ <item path="src/SimulatorSocketServer.h" ex="false" tool="3" flavor2="0">
+ </item>
<item path="src/SimulatorWindow.cpp" ex="false" tool="1" flavor2="8">
<ccTool flags="0">
</ccTool>
@@ -221,6 +227,10 @@
</incDir>
</ccTool>
</folder>
+ <item path="src/SimulatorSocketServer.cpp" ex="false" tool="1" flavor2="0">
+ </item>
+ <item path="src/SimulatorSocketServer.h" ex="false" tool="3" flavor2="0">
+ </item>
<item path="src/SimulatorWindow.cpp" ex="false" tool="1" flavor2="0">
</item>
<item path="src/SimulatorWindow.h" ex="false" tool="3" flavor2="0">
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ButtonEvent.h Thu Mar 14 16:11:08 2019 +0100
@@ -0,0 +1,29 @@
+/**
+ * Spacenav Demo Qt
+ * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#pragma once
+
+class ButtonEvent {
+public:
+ int number;
+ bool pressed;
+
+ ButtonEvent(int number, bool pressed) :
+ number(number), pressed(pressed) {
+ }
+
+};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/MotionEvent.h Thu Mar 14 16:11:08 2019 +0100
@@ -0,0 +1,30 @@
+/**
+ * Spacenav Demo Qt
+ * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#pragma once
+
+class MotionEvent {
+public:
+ int x;
+ int y;
+ int z;
+ int rx;
+ int ry;
+ int rz;
+ int type;
+ unsigned int period;
+};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/SimulatorSocketServer.cpp Thu Mar 14 16:11:08 2019 +0100
@@ -0,0 +1,29 @@
+/**
+ * Spacenav Simulator Qt
+ * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "SimulatorSocketServer.h"
+
+SimulatorSocketServer::SimulatorSocketServer() {
+}
+
+SimulatorSocketServer::SimulatorSocketServer(const SimulatorSocketServer& orig) {
+}
+
+SimulatorSocketServer::~SimulatorSocketServer() {
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/SimulatorSocketServer.h Thu Mar 14 16:11:08 2019 +0100
@@ -0,0 +1,27 @@
+/**
+ * Spacenav Simulator Qt
+ * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#pragma once
+
+class SimulatorSocketServer {
+public:
+ SimulatorSocketServer();
+ SimulatorSocketServer(const SimulatorSocketServer& orig);
+ virtual ~SimulatorSocketServer();
+private:
+
+};
--- a/src/SimulatorWindow.cpp Thu Mar 14 00:23:34 2019 +0100
+++ b/src/SimulatorWindow.cpp Thu Mar 14 16:11:08 2019 +0100
@@ -35,11 +35,14 @@
formLayout->setWidget(f++, QFormLayout::LabelRole, new QLabel("Buttons:", centralwidget));
std::vector<QString> buttonLabels = {"0", "1"};
- for (QString b : buttonLabels) {
+ for (int i = 0; i < buttonLabels.size(); i++) {
QCheckBox* button = new QCheckBox(centralwidget);
buttons.push_back(button);
- formLayout->setWidget(f, QFormLayout::LabelRole, new QLabel(b, centralwidget));
+ formLayout->setWidget(f, QFormLayout::LabelRole, new QLabel(buttonLabels[i], centralwidget));
formLayout->setWidget(f++, QFormLayout::FieldRole, button);
+ connect(button, &QCheckBox::stateChanged, [ i, this ](int state) {
+ emit buttonEvent({i, state == Qt::CheckState::Checked});
+ });
}
std::vector<QString> axisLabels = {"X", "Y", "Z"};
@@ -50,6 +53,7 @@
motions.push_back(slider);
formLayout->setWidget(f, QFormLayout::LabelRole, new QLabel(a, centralwidget));
formLayout->setWidget(f++, QFormLayout::FieldRole, slider);
+ connect(slider, &QSlider::valueChanged, this, &SimulatorWindow::sendMotionEvent);
}
@@ -59,6 +63,7 @@
rotations.push_back(slider);
formLayout->setWidget(f, QFormLayout::LabelRole, new QLabel(a, centralwidget));
formLayout->setWidget(f++, QFormLayout::FieldRole, slider);
+ connect(slider, &QSlider::valueChanged, this, &SimulatorWindow::sendMotionEvent);
}
formLayout->setWidget(f++, QFormLayout::LabelRole, new QLabel("Actions:", centralwidget));
@@ -91,3 +96,19 @@
for (QSlider* s : motions) s->setValue(0);
for (QSlider* s : rotations) s->setValue(0);
}
+
+void SimulatorWindow::sendMotionEvent() {
+ MotionEvent event;
+
+ event.x = motions[0]->value();
+ event.y = motions[1]->value();
+ event.z = motions[2]->value();
+
+ event.rx = rotations[0]->value();
+ event.ry = rotations[1]->value();
+ event.rz = rotations[2]->value();
+
+ event.period = 0; // TODO: period?
+
+ emit motionEvent(event);
+}
--- a/src/SimulatorWindow.h Thu Mar 14 00:23:34 2019 +0100
+++ b/src/SimulatorWindow.h Thu Mar 14 16:11:08 2019 +0100
@@ -23,12 +23,18 @@
#include <QtWidgets/QSlider>
#include <QtWidgets/QPushButton>
+#include "MotionEvent.h"
+#include "ButtonEvent.h"
+
class SimulatorWindow : public QMainWindow {
Q_OBJECT
public:
SimulatorWindow();
SimulatorWindow(const SimulatorWindow& orig);
virtual ~SimulatorWindow();
+signals:
+ void motionEvent(const MotionEvent e);
+ void buttonEvent(const ButtonEvent e);
private:
std::vector<QCheckBox*> buttons;
std::vector<QSlider*> motions;
@@ -38,4 +44,5 @@
private slots:
void centerAll();
+ void sendMotionEvent();
};