From 2ae959bc635aad998ea275ca09abcfe28685215b Mon Sep 17 00:00:00 2001 From: GigAnon Date: Sat, 12 Mar 2016 21:29:19 +0100 Subject: [PATCH] - Updated Majiks --- .gitignore | 2 +- remote/majiks/magiks.cpp | 63 +++-- remote/majiks/magiks.h | 12 +- remote/majiks/majiks.pro | 76 +++-- remote/majiks/majiks.pro.user | 263 ------------------ remote/majiks/serialproxy/serialproxy.cpp | 4 +- remote/majiks/serialproxy/serialproxy.h | 44 ++- .../subwindows/bluetoothmanagementwidget.cpp | 20 -- .../subwindows/bluetoothmanagementwidget.h | 3 - remote/majiks/subwindows/debugwindow.ui | 185 ------------ remote/majiks/subwindows/loggerwidget.h | 17 +- .../subwindows/movementsettingswidget.cpp | 24 +- .../subwindows/movementsettingswidget.h | 8 + .../subwindows/serialportmanagementwidget.cpp | 6 +- remote/majiks/subwindows/tablewidget.cpp | 109 ++++++-- remote/majiks/subwindows/tablewidget.h | 12 +- 16 files changed, 283 insertions(+), 565 deletions(-) delete mode 100644 remote/majiks/majiks.pro.user delete mode 100644 remote/majiks/subwindows/debugwindow.ui diff --git a/.gitignore b/.gitignore index c014f710..e1cf5c2c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ *.autosave bin/ simulation/qtcreator-files/paprikaSimulateur-build*/ -*.pro.user +*.pro.user* remote/build-*/ remote/doc/ remote/Majiks/majiks.pro.user diff --git a/remote/majiks/magiks.cpp b/remote/majiks/magiks.cpp index 12cf3724..4a9f106c 100644 --- a/remote/majiks/magiks.cpp +++ b/remote/majiks/magiks.cpp @@ -1,9 +1,9 @@ #include "magiks.h" #ifdef BLUETOOTH_USING_WINSOCK -#include "bluetoothproxy/bluetoothproxywinsock.h" + #include "bluetoothproxy/bluetoothproxywinsock.h" #else -#include "bluetoothproxy/bluetoothproxyqt5.h" + #include "bluetoothproxy/bluetoothproxyqt5.h" #endif #include "serialproxy/serialproxy.h" @@ -12,7 +12,10 @@ #include #include "subwindows/bluetoothmanagementwidget.h" -#include "subwindows/serialportmanagementwidget.h" + +#ifdef SERIAL_ENABLED + #include "subwindows/serialportmanagementwidget.h" +#endif #include "subwindows/odometrywindow.h" #include "subwindows/asservwindow.h" @@ -33,8 +36,12 @@ Magiks::Magiks(QWidget *parent): QWidget(parent) setWindowTitle(tr("Magiks - Robot remote")); #ifndef BLUETOOTH_SERVER_MODE +#ifdef SERIAL_ENABLED bool bluetoothMode = (QMessageBox::question(this, tr("Mode"), tr("Do you want to use Majiks in Bluetooth mode?")) == QMessageBox::Yes); +#else + bool bluetoothMode = true; +#endif if(bluetoothMode) { @@ -46,13 +53,21 @@ Magiks::Magiks(QWidget *parent): QWidget(parent) } else { + #ifdef SERIAL_ENABLED m_serialProxy = new SerialProxy(9600, this); + #else + m_serialProxy = nullptr; + #endif } + #ifdef SERIAL_ENABLED if(bluetoothMode) + #endif m_serialManagement = new BluetoothManagementWidget(bluetoothMode?static_cast(m_serialProxy):nullptr); + #ifdef SERIAL_ENABLED else m_serialManagement = new SerialPortManagementWidget(bluetoothMode?nullptr:static_cast(m_serialProxy)); + #endif m_odometry = new OdometryWindow(m_serialProxy); m_asserv = new AsservWindow(m_serialProxy); @@ -77,30 +92,30 @@ Magiks::Magiks(QWidget *parent): QWidget(parent) connect(m_packetProcessor, &PacketProcessor::robotPositionReceived, m_table, &TableWidget::setRobotPosition); connect(m_packetProcessor, &PacketProcessor::robotAngleReceived, m_table, &TableWidget::setRobotAngle); - connect(m_serialProxy, &AbstractSerialProxy::connected, this, &Magiks::connected); - connect(m_serialProxy, &AbstractSerialProxy::disconnected, this, &Magiks::disconnected); - connect(m_serialProxy, &AbstractSerialProxy::dataReceived, m_packetProcessor, &PacketProcessor::processData); - connect(m_serialProxy, &AbstractSerialProxy::disconnected, m_plots, &PlotWidget::clear); - - connect(m_odometry, &OdometryWindow::reseted, m_plots, &PlotWidget::clear); + connect(m_serialProxy, &AbstractSerialProxy::connected, this, [&]() { m_logger->log("Connected"); } ); + connect(m_serialProxy, &AbstractSerialProxy::disconnected, this, [&]() { m_logger->log("Disconnected"); }); + connect(m_serialProxy, &AbstractSerialProxy::dataReceived, m_packetProcessor, &PacketProcessor::processData); + connect(m_serialProxy, &AbstractSerialProxy::disconnected, m_plots, &PlotWidget::clear); - connect(m_remoteSettings, &MovementSettingsWidget::stepsUpdated, m_remote, &RemoteWidget::setSteps); + connect(m_odometry, &OdometryWindow::reseted, m_plots, &PlotWidget::clear); + connect(m_remoteSettings, &MovementSettingsWidget::stepsUpdated, m_remote, &RemoteWidget::setSteps); + connect(m_remoteSettings, &MovementSettingsWidget::tableOrientationChanged, m_table, &TableWidget::setTableOrientation); m_remoteControlTab = new QTabWidget(); - m_remoteControlTab->addTab(m_table, tr("Absolu")); - m_remoteControlTab->addTab(m_remote, tr("Relatif")); - m_remoteControlTab->addTab(m_remoteSettings,tr("Paramètres")); + m_remoteControlTab->addTab(m_table, tr("Absolute")); + m_remoteControlTab->addTab(m_remote, tr("Relative")); + m_remoteControlTab->addTab(m_remoteSettings,tr("Settings")); m_robotSettingsTab = new QTabWidget(); - m_robotSettingsTab->addTab(m_odometry, tr("Odometrie")); - m_robotSettingsTab->addTab(m_asserv, tr("Asservissement")); + m_robotSettingsTab->addTab(m_odometry, tr("Odometry")); + m_robotSettingsTab->addTab(m_asserv, tr("Control")); m_robotSettingsTab->addTab(m_watches, tr("Watches")); m_tabs = new QTabWidget(this); - m_tabs->addTab(m_serialManagement, tr("Connexion")); - m_tabs->addTab(m_robotSettingsTab, tr("Réglages")); - m_tabs->addTab(m_remoteControlTab, tr("Déplacements")); - m_tabs->addTab(m_plots, tr("Graphes")); + m_tabs->addTab(m_serialManagement, tr("Connection")); + m_tabs->addTab(m_robotSettingsTab, tr("Robot settings")); + m_tabs->addTab(m_remoteControlTab, tr("Movements")); + m_tabs->addTab(m_plots, tr("Graphs")); m_tabs->addTab(m_logger, tr("Logs")); QVBoxLayout* layout = new QVBoxLayout(this); @@ -110,13 +125,3 @@ Magiks::Magiks(QWidget *parent): QWidget(parent) BluetoothTestServer* server = new BluetoothTestServer(this); #endif } - -void Magiks::disconnected() -{ - m_logger->log("Disconnected"); -} - -void Magiks::connected() -{ - m_logger->log("Connected"); -} diff --git a/remote/majiks/magiks.h b/remote/majiks/magiks.h index 73397b17..28082709 100644 --- a/remote/majiks/magiks.h +++ b/remote/majiks/magiks.h @@ -19,17 +19,23 @@ class MovementSettingsWidget; class QTabWidget; +/** + * @brief The application's main class. + * + * This class represents the main window. It builds everything else, connects signals to slots, and manages the tabs. + */ class Magiks: public QWidget { Q_OBJECT public: + /** + * @brief Constructor + * @param parent + */ explicit Magiks(QWidget *parent = nullptr); private: - void connected(); - void disconnected(); - AbstractSerialProxy* m_serialProxy; PacketProcessor* m_packetProcessor; diff --git a/remote/majiks/majiks.pro b/remote/majiks/majiks.pro index 5d4d0a17..039de396 100644 --- a/remote/majiks/majiks.pro +++ b/remote/majiks/majiks.pro @@ -1,36 +1,62 @@ -QT += core gui widgets -QT += bluetooth serialport +TARGET = majiks +TEMPLATE = app +QT += core gui widgets +QT += bluetooth CONFIG += console c++11 warn_on +# By default, QtSerialPort is not compiled with Qt for Android. +# Since direct serial communications are only usefull for desktops anyway, it's easier to disable it entierely. +!android:CONFIG += serial + # Disabled because of an obnoxious bug in GCC (struct A = {0} triggers the warning even though it's legal) win32-g++:QMAKE_CXXFLAGS += -Wno-missing-field-initializers -TARGET = majiks -TEMPLATE = app - -#NB: you HAVE to set QWT_ROOT as an env variable yourself +# The config when serial coms are enabled +serial { + QT += serialport + DEFINES += SERIAL_ENABLED + + SOURCES += serialproxy/serialproxy.cpp \ + subwindows/serialportmanagementwidget.cpp + HEADERS += serialproxy/serialproxy.h \ + subwindows/serialportmanagementwidget.h +} + +# Check if QWT_ROOT is defined as an environment variable +_QWT_ROOT = $$(QWT_ROOT) +isEmpty(_QWT_ROOT) { + error("Please set QWT_ROOT as an environment variable.") +} +# NB: you HAVE to set QWT_ROOT as an env variable yourself # (it points to the folder where you compiled Qwt) +# We are not using the 'module' install because it is broken on several platforms +# qwt.prf should setup everything nicely... include ( $(QWT_ROOT)/features/qwt.prf ) LIBS += -lqwt -#Qwt is VERY finicky when it comes to Android... +# Qwt is VERY finicky when it comes to Android... +# There has to be a better way to include Qt5PrintSupport.so and Qt5OpenGL.so by default directly from Qt, but I couldn't find it. android:ANDROID_EXTRA_LIBS += $$(QWT_ROOT)/lib/libqwt.so $$(QWT_ROOT)/lib/libQt5PrintSupport.so $$(QWT_ROOT)/lib/libQt5OpenGL.so +# qwt.prf is broken for Android (the config is confused by the X-compil and uses Unix settings instead of the host's...) android:INCLUDEPATH += $$(QWT_ROOT)/include android:QMAKE_LIBDIR += $$(QWT_ROOT)/lib - +# For KrabiPacket INCLUDEPATH += ../../stm32/include/hardware - - -win32:HEADERS += bluetoothproxy/bluetoothproxywinsock.h -win32:SOURCES += bluetoothproxy/bluetoothproxywinsock.cpp -win32:DEFINES += BLUETOOTH_USING_WINSOCK -win32:LIBS += -lws2_32 - DEFINES += BLUETOOTH +# Winsock config +win32 { + HEADERS += bluetoothproxy/bluetoothproxywinsock.h + SOURCES += bluetoothproxy/bluetoothproxywinsock.cpp + DEFINES += BLUETOOTH_USING_WINSOCK + LIBS += -lws2_32 +} + +# Sources files used by every config +# (note: used by both QtCreator for the project view AND by the linker - don't forget to call qmake when changing those) SOURCES += main.cpp \ magiks.cpp \ ../../stm32/src/hardware/krabipacket.cpp \ @@ -47,14 +73,13 @@ SOURCES += main.cpp \ packetprocessor.cpp \ timemaster.cpp \ bluetoothtestserver.cpp \ - subwindows/movementsettingswidget.cpp \ - serialproxy/abstractserialproxy.cpp \ - serialproxy/serialproxy.cpp \ - subwindows/serialmanagementwidget.cpp \ - subwindows/serialportmanagementwidget.cpp + subwindows/movementsettingswidget.cpp \ + serialproxy/abstractserialproxy.cpp \ + subwindows/serialmanagementwidget.cpp - +# Headers files used by every config +# (note: only useful for the project view in QtCreator) HEADERS += magiks.h \ ../../stm32/include/hardware/krabipacket.h \ bluetoothproxy/bluetoothproxy.h \ @@ -70,17 +95,14 @@ HEADERS += magiks.h \ packetprocessor.h \ timemaster.h \ bluetoothtestserver.h \ - subwindows/movementsettingswidget.h \ - serialproxy/abstractserialproxy.h \ - serialproxy/serialproxy.h \ - subwindows/serialmanagementwidget.h \ - subwindows/serialportmanagementwidget.h + subwindows/movementsettingswidget.h \ + serialproxy/abstractserialproxy.h \ + subwindows/serialmanagementwidget.h FORMS += \ subwindows/asservwindow.ui \ - subwindows/debugwindow.ui \ subwindows/odometrywindow.ui \ subwindows/watchwindow.ui diff --git a/remote/majiks/majiks.pro.user b/remote/majiks/majiks.pro.user deleted file mode 100644 index 610f08be..00000000 --- a/remote/majiks/majiks.pro.user +++ /dev/null @@ -1,263 +0,0 @@ - - - - - - EnvironmentId - {46860dce-a80b-44ec-8804-ace4954c84ef} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.PluginSettings - - - - ProjectExplorer.Project.Target.0 - - Desktop Qt 5.5.0 MSVC2013 64bit - Desktop Qt 5.5.0 MSVC2013 64bit - qt.55.win64_msvc2013_64_kit - 0 - 0 - 0 - - C:/Data/Robotique/Git/gitRobotique/remote/build-majiks-Desktop_Qt_5_5_0_MSVC2013_64bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - QWT_ROOT=C:\Qwt-6.1.2-qt-5.5.0-VS2015-x64/ - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - C:/Data/Robotique/Git/gitRobotique/remote/build-majiks-Desktop_Qt_5_5_0_MSVC2013_64bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - QWT_ROOT=C:\Qwt-6.1.2-qt-5.5.0-VS2015-x64/ - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 2 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - majiks - - Qt4ProjectManager.Qt4RunConfiguration:C:/Data/Robotique/Git/gitRobotique/remote/majiks/majiks.pro - - majiks.pro - false - true - - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 18 - - - Version - 18 - - diff --git a/remote/majiks/serialproxy/serialproxy.cpp b/remote/majiks/serialproxy/serialproxy.cpp index 6c18cbb3..ef5bfb2a 100644 --- a/remote/majiks/serialproxy/serialproxy.cpp +++ b/remote/majiks/serialproxy/serialproxy.cpp @@ -10,10 +10,10 @@ SerialProxy::SerialProxy(qint32 baudrate, QObject *parent): AbstractSerialProxy( m_serialPort = new QSerialPort(this); connect(m_serialPort, &QSerialPort::readyRead, this, &SerialProxy::readData); - setBaudrate(baudrate); } +#ifdef SERIAL_ENABLED bool SerialProxy::setBaudrate(qint32 baudrate) { return !m_serialPort->setBaudRate(baudrate); @@ -92,3 +92,5 @@ void SerialProxy::sendData(KrabiPacket& data) m_serialPort->write(binData); } + +#endif diff --git a/remote/majiks/serialproxy/serialproxy.h b/remote/majiks/serialproxy/serialproxy.h index ede7ca8e..44b3e77a 100644 --- a/remote/majiks/serialproxy/serialproxy.h +++ b/remote/majiks/serialproxy/serialproxy.h @@ -5,24 +5,66 @@ class QSerialPort; +/** + * @brief This class provides an implementation of AbstractSerialProxy as a physical serial connection (COM) + * + * This class provides an implementation of AbstractSerialProxy as a physical serial connection (COM). + * Since it uses QtSerial, it should work with most plateforms. + * Note Qt is not always compiled with QtSerial enabled (it isn't on Android). You can disable serial support entierely through majiks.pro. + */ class SerialProxy : public AbstractSerialProxy { public: + /** + * @brief Constructor + * @param baudrate The baudrate to use. It is preferable (but not mandatory) to use constants from QSerialPort::BaudRate. + * @param parent The parent object + */ SerialProxy(qint32 baudrate = 9600, QObject* parent = nullptr); virtual void sendData(KrabiPacket& data); + /** + * @brief It is preferable (but not mandatory) to use constants from QSerialPort::BaudRate. + * @param baudrate + * @return True if an error happened (i.e. invalid baudrate), false otherwise. + */ bool setBaudrate(qint32 baudrate); + /** + * @brief Return the baudrate + * @return + */ qint32 getBaudrate() const; + /** + * @brief Returns the port name as a QString + * @return The port name or an empty QString + */ QString getPortName() const; - bool open(QString port); + /** + * @brief Open the serial port. Any previous connection is dropped. + * @param The port name to use. If empty, uses any available port. + * @return True on error, false otherwise + * @see close isOpen + */ + bool open(QString port = QString()); + /** + * @brief Close the current connection. + * @see isOpen open + */ void close(); + /** + * @return True if a valid connection to a serial port exists, false otherwise. + * @see open close + */ bool isOpen() const; protected: + /** + * @brief Handles the incomming data + */ void readData(); private: diff --git a/remote/majiks/subwindows/bluetoothmanagementwidget.cpp b/remote/majiks/subwindows/bluetoothmanagementwidget.cpp index 5e9f2e0b..5e49b9a3 100644 --- a/remote/majiks/subwindows/bluetoothmanagementwidget.cpp +++ b/remote/majiks/subwindows/bluetoothmanagementwidget.cpp @@ -19,9 +19,6 @@ BluetoothManagementWidget::BluetoothManagementWidget(BluetoothProxy* bluetoothPr m_bluetoothAvLabel = new QLabel(this); m_connectionLabel = new QLabel(this); - //Debug - m_sendButton = new QPushButton(tr("Send"), this); - m_scanButton = new QPushButton(tr("Scan"), this); m_connectButton = new QPushButton(this); m_checkBluetoothButton = new QPushButton(tr("Check Bluetooth"), this); @@ -55,7 +52,6 @@ BluetoothManagementWidget::BluetoothManagementWidget(BluetoothProxy* bluetoothPr layout->addLayout(btCxLay); layout->addWidget(m_scanButton); layout->addWidget(m_detectedDevices); - layout->addWidget(m_sendButton); connect(m_connectButton, &QPushButton::clicked, this, &BluetoothManagementWidget::on_connectButton_clicked); connect(m_checkBluetoothButton, &QPushButton::clicked, this, &BluetoothManagementWidget::checkBluetoothAvailability); @@ -70,8 +66,6 @@ BluetoothManagementWidget::BluetoothManagementWidget(BluetoothProxy* bluetoothPr connect(m_UUIDInput, &QLineEdit::textChanged, this, &BluetoothManagementWidget::changeUUID); - //Debug - connect(m_sendButton, &QPushButton::clicked, this, &BluetoothManagementWidget::sendTest); //m_UUIDInput->setText("B62C4E8D-62CC-404B-BBBF-BF3E3BBB1374"); m_UUIDInput->setText("00001101-0000-1000-8000-00805F9B34FB"); @@ -128,7 +122,6 @@ void BluetoothManagementWidget::checkBluetoothAvailability() btAv = m_bluetoothProxy->isBluetoothAvailable(); m_scanButton->setEnabled(btAv); - m_sendButton->setEnabled(btAv); m_detectedDevices->setEnabled(btAv); m_connectButton->setEnabled(btAv); m_UUIDInput->setEnabled(btAv); @@ -181,16 +174,3 @@ QString BluetoothManagementWidget::getSelectedAddress() const return m_detectedDevices->item(row, 1)->data(BluetoothManagementWidget::ADDRESS_DATA_INDEX).toString(); } - - -//Debug -void BluetoothManagementWidget::sendTest() -{ - if(!m_bluetoothProxy) - return; - - KrabiPacket packet(KrabiPacket::LOG_DEBUG); - packet.addString("test"); - - m_bluetoothProxy->sendData(packet); -} diff --git a/remote/majiks/subwindows/bluetoothmanagementwidget.h b/remote/majiks/subwindows/bluetoothmanagementwidget.h index 1941ec1d..cbc1ec98 100644 --- a/remote/majiks/subwindows/bluetoothmanagementwidget.h +++ b/remote/majiks/subwindows/bluetoothmanagementwidget.h @@ -18,9 +18,6 @@ class BluetoothManagementWidget: public SerialManagementWidget QString getSelectedAddress() const; private: - //Debug - void sendTest(); - QPushButton* m_sendButton; void checkBluetoothAvailability(); void checkConnectionStatus(); diff --git a/remote/majiks/subwindows/debugwindow.ui b/remote/majiks/subwindows/debugwindow.ui deleted file mode 100644 index c0d76a46..00000000 --- a/remote/majiks/subwindows/debugwindow.ui +++ /dev/null @@ -1,185 +0,0 @@ - - - DebugWindow - - - - 0 - 0 - 800 - 600 - - - - MainWindow - - - - - - - ... - - - - - - - - - 0 - 0 - 800 - 25 - - - - - Perspectives - - - - - - - - Views - - - - - - - - - - - Settings - - - - - - - - - - - - - - - - Simulateur - - - - - Odometrie - - - - - Asservissement - - - - - true - - - false - - - Display route - - - - - true - - - Hide table - - - - - Reset objects - - - - - Remove objects - - - - - true - - - true - - - Display strategy - - - - - true - - - Remote Mod - - - - - true - - - Bluetooth Scanner - - - - - true - - - Bluetooth Interface - - - - - true - - - Odometrie - - - - - true - - - Asserv - - - - - true - - - Sharps - - - - - true - - - Watches - - - - - - diff --git a/remote/majiks/subwindows/loggerwidget.h b/remote/majiks/subwindows/loggerwidget.h index 5ac100bf..18d73be9 100644 --- a/remote/majiks/subwindows/loggerwidget.h +++ b/remote/majiks/subwindows/loggerwidget.h @@ -6,14 +6,29 @@ class QTextEdit; +/** + * @brief A simple widget to display logs. + */ class LoggerWidget : public QWidget { - Q_OBJECT + Q_OBJECT public: + /** + * @brief Constructor + * @param parent The parent widget + */ explicit LoggerWidget(QWidget *parent = nullptr); + /** + * @brief Add a line to the log + * @param text The text to add + * @param isDebug If set, this line will be displayed as 'debug' + */ void log(const QString& text, bool isDebug = false); + /** + * @return The entierety of the logs + */ QString getLogs() const; private: diff --git a/remote/majiks/subwindows/movementsettingswidget.cpp b/remote/majiks/subwindows/movementsettingswidget.cpp index 89282341..edd2ae38 100644 --- a/remote/majiks/subwindows/movementsettingswidget.cpp +++ b/remote/majiks/subwindows/movementsettingswidget.cpp @@ -3,12 +3,15 @@ #include #include #include +#include #include #include MovementSettingsWidget::MovementSettingsWidget(QWidget *parent) : QWidget(parent) { - m_stepsGB = new QGroupBox(tr("Pas de déplacement"), this); + QVBoxLayout* layout = new QVBoxLayout(this); + + m_stepsGB = new QGroupBox(tr("Movement steps"), this); m_angularStepSB = new QDoubleSpinBox(this); m_angularStepSB->setSuffix(tr(" °")); @@ -25,8 +28,6 @@ MovementSettingsWidget::MovementSettingsWidget(QWidget *parent) : QWidget(parent connect(m_angularStepSB, static_cast(&QDoubleSpinBox::valueChanged), this, &MovementSettingsWidget::on_stepsUpdated); connect(m_linearStepSB, static_cast(&QDoubleSpinBox::valueChanged), this, &MovementSettingsWidget::on_stepsUpdated); - QVBoxLayout* layout = new QVBoxLayout(this); - QGridLayout* stepsLayout = new QGridLayout(m_stepsGB); stepsLayout->addWidget(new QLabel(tr("Distance")), 1, 1); stepsLayout->addWidget(new QLabel(tr("Angle")), 1, 2); @@ -34,9 +35,26 @@ MovementSettingsWidget::MovementSettingsWidget(QWidget *parent) : QWidget(parent stepsLayout->addWidget(m_angularStepSB, 2, 2); layout->addWidget(m_stepsGB); + + + m_tableGB = new QGroupBox(tr("Table settings"), this); + + m_tableOrientationCB = new QCheckBox(tr("Swap table axes"), this); + + connect(m_tableOrientationCB, &QCheckBox::toggled, this, &MovementSettingsWidget::changeTableOrientation); + + QGridLayout* tableSettingsLayout = new QGridLayout(m_tableGB); + tableSettingsLayout->addWidget(m_tableOrientationCB, 1, 1); + + layout->addWidget(m_tableGB); layout->addStretch(); } +void MovementSettingsWidget::changeTableOrientation(bool rotated) +{ + emit tableOrientationChanged(rotated); +} + void MovementSettingsWidget::on_stepsUpdated(double) { diff --git a/remote/majiks/subwindows/movementsettingswidget.h b/remote/majiks/subwindows/movementsettingswidget.h index 6dbe082e..ea31ad19 100644 --- a/remote/majiks/subwindows/movementsettingswidget.h +++ b/remote/majiks/subwindows/movementsettingswidget.h @@ -5,6 +5,7 @@ class QDoubleSpinBox; class QGroupBox; +class QCheckBox; class MovementSettingsWidget: public QWidget { @@ -16,12 +17,19 @@ class MovementSettingsWidget: public QWidget void stepsUpdated(float linearStep, float angularStep); + void tableOrientationChanged(bool rotated); + private: void on_stepsUpdated(double); + void changeTableOrientation(bool rotated); + QGroupBox* m_stepsGB; QDoubleSpinBox* m_angularStepSB; QDoubleSpinBox* m_linearStepSB; + + QGroupBox* m_tableGB; + QCheckBox* m_tableOrientationCB; }; #endif // MOVEMENTSETTINGSWIDGET_H diff --git a/remote/majiks/subwindows/serialportmanagementwidget.cpp b/remote/majiks/subwindows/serialportmanagementwidget.cpp index 4ede2691..96909c4f 100644 --- a/remote/majiks/subwindows/serialportmanagementwidget.cpp +++ b/remote/majiks/subwindows/serialportmanagementwidget.cpp @@ -2,7 +2,9 @@ #include "serialproxy/serialproxy.h" +#ifdef SERIAL_ENABLED #include +#endif #include #include @@ -58,16 +60,18 @@ void SerialPortManagementWidget::updateConnectionStatus() void SerialPortManagementWidget::updateAvailablePorts() { + m_portsCB->clear(); + #ifdef SERIAL_ENABLED QString current = getSelectedPort(); QList l = QSerialPortInfo::availablePorts(); - m_portsCB->clear(); for(auto port: l) m_portsCB->addItem(port.portName()); m_portsCB->setCurrentText(current); + #endif } QString SerialPortManagementWidget::getSelectedPort() const diff --git a/remote/majiks/subwindows/tablewidget.cpp b/remote/majiks/subwindows/tablewidget.cpp index e2504056..b62e408c 100644 --- a/remote/majiks/subwindows/tablewidget.cpp +++ b/remote/majiks/subwindows/tablewidget.cpp @@ -3,6 +3,8 @@ #include "serialproxy/abstractserialproxy.h" #include "loggerwidget.h" +#include + #include #include #include @@ -10,14 +12,37 @@ #include TableWidget::TableWidget(AbstractSerialProxy *serialProxy, QWidget* parent): QWidget(parent), -TABLE_LENGTH(3000), TABLE_WIDTH(2000), -TABLE_LENGTH_F(static_cast(TABLE_LENGTH)), TABLE_WIDTH_F(static_cast(TABLE_WIDTH)) +TABLE_LENGTH(3000), TABLE_WIDTH(2000) { m_serialProxy = serialProxy; + setTableOrientation(false); setRobotVisible(true); setRobotAngle(0.f); - setRobotPosition(QPointF(TABLE_LENGTH_F/2.f, TABLE_WIDTH_F/2.f)); + setRobotPosition(QPointF(TABLE_LENGTH/4.f, 3.f*TABLE_WIDTH/4.f)); +} + +void TableWidget::setTableOrientation(bool rotated) +{ + m_tableIsRotated = rotated; + update(); +} + +bool TableWidget::isTableRotated() const +{ + return m_tableIsRotated; +} + +QPointF TableWidget::getOrientatedMaximaF() const +{ + return QPointF(getOrientatedMaxima()); +} + +QPoint TableWidget::getOrientatedMaxima() const +{ + if(isTableRotated()) + return QPoint(TABLE_WIDTH, TABLE_LENGTH); + return QPoint(TABLE_LENGTH, TABLE_WIDTH); } void TableWidget::setRobotVisible(bool visible) @@ -36,10 +61,15 @@ void TableWidget::setRobotAngle(float angle) update(); } +float TableWidget::getRobotAngle() const +{ + return m_robotAngle; +} + void TableWidget::setRobotPosition(const QPointF& position) { - m_robotPosition.rx() = qBound(0.f, position.x(), TABLE_LENGTH_F); - m_robotPosition.ry() = qBound(0.f, position.y(), TABLE_WIDTH_F); + m_robotPosition.rx() = qBound(0.f, position.x(), static_cast(TABLE_LENGTH)); + m_robotPosition.ry() = qBound(0.f, position.y(), static_cast(TABLE_WIDTH)); update(); } @@ -50,13 +80,14 @@ QPointF TableWidget::getRobotPosition() const QPointF TableWidget::getRobotRelativePosition() const { - return QPointF(m_robotPosition.x()/TABLE_LENGTH_F, m_robotPosition.y()/TABLE_WIDTH_F); + return QPointF(m_robotPosition.x()/static_cast(TABLE_LENGTH), m_robotPosition.y()/static_cast(TABLE_WIDTH)); } void TableWidget::mouseDoubleClickEvent(QMouseEvent *evt) { - float x = static_cast(evt->x() * TABLE_LENGTH_F)/(size().width()); - float y = static_cast(evt->y() * TABLE_WIDTH_F) /(size().height()); + QPointF lw = getOrientatedMaximaF(); + float x = static_cast(evt->x() * lw.x()) /(size().width()); + float y = static_cast(evt->y() * lw.y()) /(size().height()); if (evt->button() == Qt::LeftButton) { @@ -73,9 +104,11 @@ void TableWidget::mouseDoubleClickEvent(QMouseEvent *evt) void TableWidget::paintEvent(QPaintEvent *evt) { + QPointF lw = getOrientatedMaxima(); + QPainter p(this); p.setRenderHints(QPainter::Antialiasing, true); - p.setWindow(QRect(0,0,TABLE_LENGTH,TABLE_WIDTH)); + p.setWindow(QRect(0,0,lw.x(),lw.y())); p.setWorldMatrixEnabled(true); QFont font; @@ -84,33 +117,33 @@ void TableWidget::paintEvent(QPaintEvent *evt) p.setOpacity(1); p.setPen(QColor(Qt::gray)); - p.fillRect(QRect(0, 0, TABLE_LENGTH, TABLE_WIDTH), QBrush(Qt::gray)); + p.fillRect(QRect(0, 0, lw.x(), lw.y()), QBrush(Qt::gray)); // draw a grid // 100 mm p.setOpacity(0.25); p.setPen(QColor(Qt::white)); - for(unsigned int i=100; iignore(); diff --git a/remote/majiks/subwindows/tablewidget.h b/remote/majiks/subwindows/tablewidget.h index ea13c2d5..f5b57b92 100644 --- a/remote/majiks/subwindows/tablewidget.h +++ b/remote/majiks/subwindows/tablewidget.h @@ -19,23 +19,27 @@ class TableWidget: public QWidget void setRobotVisible(bool visible); bool isRobotVisible() const; + void setTableOrientation(bool rotated); + bool isTableRotated() const; + protected: void paintEvent(QPaintEvent*); void mouseDoubleClickEvent(QMouseEvent*); + QPoint getOrientatedMaxima() const; + QPointF getOrientatedMaximaF() const; + private: const unsigned int TABLE_LENGTH; const unsigned int TABLE_WIDTH; - const float TABLE_LENGTH_F; - const float TABLE_WIDTH_F; - - QPointF m_robotPosition; float m_robotAngle; bool m_robotVisible; + bool m_tableIsRotated; + AbstractSerialProxy* m_serialProxy; }; -- GitLab