From 32e9a7937e72e7f97c094ae7726825916dbdde6b Mon Sep 17 00:00:00 2001 From: Guenter Schwann <guenter@vikingsoftware.com> Date: Wed, 15 Feb 2023 16:27:20 +0100 Subject: [PATCH 1/2] Create skeleton of the IV streamer app --- src/applications/CMakeLists.txt | 1 + src/applications/ivstreaming/CMakeLists.txt | 38 ++++++++++++ .../ivstreaming/ivstreamingwindow.cpp | 58 +++++++++++++++++++ .../ivstreaming/ivstreamingwindow.h | 54 +++++++++++++++++ .../ivstreaming/ivstreamingwindow.ui | 37 ++++++++++++ src/applications/ivstreaming/main.cpp | 55 ++++++++++++++++++ src/libs/libiveditor/interfacedocument.cpp | 3 + src/libs/shared/ui/graphicsviewbase.cpp | 41 +++++++++++++ src/libs/shared/ui/graphicsviewbase.h | 2 + 9 files changed, 289 insertions(+) create mode 100644 src/applications/ivstreaming/CMakeLists.txt create mode 100644 src/applications/ivstreaming/ivstreamingwindow.cpp create mode 100644 src/applications/ivstreaming/ivstreamingwindow.h create mode 100644 src/applications/ivstreaming/ivstreamingwindow.ui create mode 100644 src/applications/ivstreaming/main.cpp diff --git a/src/applications/CMakeLists.txt b/src/applications/CMakeLists.txt index 236046259c..64cee0bb77 100644 --- a/src/applications/CMakeLists.txt +++ b/src/applications/CMakeLists.txt @@ -2,6 +2,7 @@ add_subdirectory(aadlconverter) add_subdirectory(dvconverter) add_subdirectory(dveditor) add_subdirectory(iveditor) +add_subdirectory(ivstreaming) add_subdirectory(mscconverter) add_subdirectory(msceditor) add_subdirectory(msctosdlconverter) diff --git a/src/applications/ivstreaming/CMakeLists.txt b/src/applications/ivstreaming/CMakeLists.txt new file mode 100644 index 0000000000..483bfb2110 --- /dev/null +++ b/src/applications/ivstreaming/CMakeLists.txt @@ -0,0 +1,38 @@ +set(APP_NAME ivstreaming) +project(${APP_NAME}) + +add_executable(${APP_NAME}) + +target_sources(${APP_NAME} PRIVATE + main.cpp + ivstreamingwindow.cpp + ivstreamingwindow.h + ivstreamingwindow.ui +) + +target_link_libraries(${APP_NAME} PUBLIC + libiveditor + ${QT_CORE} + ${QT_GUI} + ${QT_WIDGETS} +) + +target_include_directories(${APP_NAME} PRIVATE + . +) + +source_group("Designer Files" REGULAR_EXPRESSION ".*.ui$") + +set_target_properties(${APP_NAME} + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" +) + +if (WIN32) + if(CMAKE_BUILD_TYPE STREQUAL "Release") + # hide the console window for release builds + set_property(TARGET ${APP_NAME} PROPERTY WIN32_EXECUTABLE true) + endif() +endif() + +install(TARGETS ${APP_NAME} DESTINATION bin) diff --git a/src/applications/ivstreaming/ivstreamingwindow.cpp b/src/applications/ivstreaming/ivstreamingwindow.cpp new file mode 100644 index 0000000000..611ceeafb9 --- /dev/null +++ b/src/applications/ivstreaming/ivstreamingwindow.cpp @@ -0,0 +1,58 @@ +/* + Copyright (C) 2023 European Space Agency - <maxime.perrotin@esa.int> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this program. If not, see <https://www.gnu.org/licenses/lgpl-2.1.html>. +*/ + +#include "ivstreamingwindow.h" + +#include "interfacedocument.h" +#include "ui_ivstreamingwindow.h" + +#include <QApplication> + +namespace iv { + +IVStreamingWindow::IVStreamingWindow(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::IVStreamingWindow) + , m_document(new ive::InterfaceDocument(this)) +{ + ui->setupUi(this); + ui->graphicsView->setInteractive(false); + ui->graphicsView->setScene(m_document->scene()); + m_document->load("./interfaceview.xml"); +} + +IVStreamingWindow::~IVStreamingWindow() +{ + delete ui; +} + +/** + * Starts the websocket for remote control at the port \p + * Default port is 34633 + */ +bool IVStreamingWindow::startRemoteControl(quint16 port) +{ + return true; +} + +void IVStreamingWindow::closeEvent(QCloseEvent *e) +{ + QMainWindow::closeEvent(e); + QApplication::quit(); +} + +} diff --git a/src/applications/ivstreaming/ivstreamingwindow.h b/src/applications/ivstreaming/ivstreamingwindow.h new file mode 100644 index 0000000000..039c68939f --- /dev/null +++ b/src/applications/ivstreaming/ivstreamingwindow.h @@ -0,0 +1,54 @@ +/* + Copyright (C) 2023 European Space Agency - <maxime.perrotin@esa.int> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this program. If not, see <https://www.gnu.org/licenses/lgpl-2.1.html>. +*/ + +#pragma once + +#include <QMainWindow> +#include <memory> + +namespace ive { +class InterfaceDocument; +} + +namespace Ui { +class IVStreamingWindow; +} + +namespace iv { + +/** + * This is the main window class for the IV stream remote control. + * It inclues the model as well. + */ +class IVStreamingWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit IVStreamingWindow(QWidget *parent = nullptr); + ~IVStreamingWindow(); + + bool startRemoteControl(quint16 port); + +private: + void closeEvent(QCloseEvent *e) override; + + Ui::IVStreamingWindow *ui = nullptr; + ive::InterfaceDocument *m_document = nullptr; +}; + +} diff --git a/src/applications/ivstreaming/ivstreamingwindow.ui b/src/applications/ivstreaming/ivstreamingwindow.ui new file mode 100644 index 0000000000..137e98b4f6 --- /dev/null +++ b/src/applications/ivstreaming/ivstreamingwindow.ui @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>IVStreamingWindow</class> + <widget class="QMainWindow" name="IVStreamingWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>800</width> + <height>600</height> + </rect> + </property> + <property name="windowTitle"> + <string>IV Streaming</string> + </property> + <property name="layoutDirection"> + <enum>Qt::LeftToRight</enum> + </property> + <widget class="QWidget" name="centralWidget"> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="shared::ui::GraphicsViewBase" name="graphicsView"/> + </item> + </layout> + </widget> + </widget> + <layoutdefault spacing="6" margin="11"/> + <customwidgets> + <customwidget> + <class>shared::ui::GraphicsViewBase</class> + <extends>QGraphicsView</extends> + <header>ui/graphicsviewbase.h</header> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> diff --git a/src/applications/ivstreaming/main.cpp b/src/applications/ivstreaming/main.cpp new file mode 100644 index 0000000000..3609d58ffd --- /dev/null +++ b/src/applications/ivstreaming/main.cpp @@ -0,0 +1,55 @@ +/* + Copyright (C) 2023 European Space Agency - <maxime.perrotin@esa.int> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this program. If not, see <https://www.gnu.org/licenses/lgpl-2.1.html>. +*/ + +#include "commandlineparser.h" +#include "iveditor.h" +#include "ivstreamingwindow.h" +#include "scversion.h" +#include "sharedlibrary.h" + +#include <QApplication> + +int main(int argc, char *argv[]) +{ + shared::initSharedLibrary(); + ive::initIVEditor(); + + QApplication a(argc, argv); + a.setOrganizationName(SC_ORGANISATION); + a.setOrganizationDomain(SC_ORGANISATION_DOMAIN); + a.setApplicationVersion(spaceCreatorVersion); + a.setApplicationName(QObject::tr("IV Streaming")); + + shared::CommandLineParser cmdParser; + cmdParser.handlePositional(shared::CommandLineParser::Positional::StartRemoteControl); + cmdParser.process(a.arguments()); + + const QString portString = cmdParser.value(shared::CommandLineParser::Positional::StartRemoteControl); + quint16 port = portString.toUShort(); + if (port <= 1000) { + port = 34633; + } + + iv::IVStreamingWindow window; + if (!window.startRemoteControl(port)) { + return -1; + } + + window.show(); + + return a.exec(); +} diff --git a/src/libs/libiveditor/interfacedocument.cpp b/src/libs/libiveditor/interfacedocument.cpp index 61fee885ac..08e2cb323b 100644 --- a/src/libs/libiveditor/interfacedocument.cpp +++ b/src/libs/libiveditor/interfacedocument.cpp @@ -979,6 +979,9 @@ void InterfaceDocument::showNIYGUI(const QString &title) void InterfaceDocument::onSceneSelectionChanged(const QList<shared::Id> &selectedObjects) { + if (!d->objectsVisualizationModel || !d->objectsSelectionModel) { + return; + } QItemSelection itemSelection; for (auto id : selectedObjects) { const QModelIndex idx = d->objectsVisualizationModel->indexFromItem(d->objectsVisualizationModel->getItem(id)); diff --git a/src/libs/shared/ui/graphicsviewbase.cpp b/src/libs/shared/ui/graphicsviewbase.cpp index daf5fa372e..0903963132 100644 --- a/src/libs/shared/ui/graphicsviewbase.cpp +++ b/src/libs/shared/ui/graphicsviewbase.cpp @@ -33,6 +33,7 @@ struct GraphicsViewBase::GraphicsViewBasePrivate { bool panning = false; QPointF lastMousePosition; + bool interactive = true; }; GraphicsViewBase::GraphicsViewBase(QGraphicsScene *scene, QWidget *parent) @@ -84,6 +85,15 @@ qreal GraphicsViewBase::zoomStepPercent() const return d->zoomStepPercent; } +/** + * Enables/disables mouse and key interaction (selection, editing, ...). Navigation (millde mouse button) is still + * always possible. + */ +void GraphicsViewBase::setInteractive(bool on) +{ + d->interactive = on; +} + /*! * \brief GraphicsViewBase::setZoom Set the current zoom percentage and update the view * \a percent @@ -128,6 +138,12 @@ void GraphicsViewBase::mousePressEvent(QMouseEvent *event) if (event->buttons() == Qt::MiddleButton) { d->panning = true; d->lastMousePosition = event->localPos(); + event->accept(); + return; + } + + if (!d->interactive) { + return; } QGraphicsView::mousePressEvent(event); @@ -140,6 +156,7 @@ void GraphicsViewBase::mouseMoveEvent(QMouseEvent *event) QPointF translation = event->localPos() - d->lastMousePosition; translate(translation.x(), translation.y()); d->lastMousePosition = event->localPos(); + event->accept(); } // Show the coordinates list in the statusbar @@ -162,12 +179,20 @@ void GraphicsViewBase::mouseMoveEvent(QMouseEvent *event) Q_EMIT mouseMoved(info); + if (!d->interactive) { + return; + } + QGraphicsView::mouseMoveEvent(event); } void GraphicsViewBase::mouseReleaseEvent(QMouseEvent *event) { d->panning = false; + if (!d->interactive) { + return; + } + QGraphicsView::mouseReleaseEvent(event); } @@ -189,6 +214,10 @@ void GraphicsViewBase::wheelEvent(QWheelEvent *event) void GraphicsViewBase::keyPressEvent(QKeyEvent *event) { + if (!d->interactive) { + return; + } + if (event->modifiers() & Qt::ControlModifier && (event->key() == Qt::Key_Plus || event->key() == Qt::Key_Minus)) { setZoom(d->zoomPercent + (event->key() == Qt::Key_Plus ? zoomStepPercent() : -zoomStepPercent())); event->accept(); @@ -234,16 +263,28 @@ void GraphicsViewBase::drawBackground(QPainter *painter, const QRectF &rect) void GraphicsViewBase::dragEnterEvent(QDragEnterEvent *event) { + if (!d->interactive) { + return; + } + event->acceptProposedAction(); } void GraphicsViewBase::dragMoveEvent(QDragMoveEvent *event) { + if (!d->interactive) { + return; + } + event->acceptProposedAction(); } void GraphicsViewBase::dropEvent(QDropEvent *event) { + if (!d->interactive) { + return; + } + if (auto mimeData = qobject_cast<const DropData *>(event->mimeData())) { if (mimeData->dropType == DropData::Type::ImportableType) { Q_EMIT importEntity(mimeData->entityId, mapToScene(event->pos())); diff --git a/src/libs/shared/ui/graphicsviewbase.h b/src/libs/shared/ui/graphicsviewbase.h index 446edddc97..fb3f990b34 100644 --- a/src/libs/shared/ui/graphicsviewbase.h +++ b/src/libs/shared/ui/graphicsviewbase.h @@ -43,6 +43,8 @@ public: qreal maxZoomPercent() const; qreal zoomStepPercent() const; + void setInteractive(bool on); + Q_SIGNALS: void mouseMoved(const QString &coordsInfo); void zoomChanged(qreal percent); -- GitLab From 726628e96df35c19923fb537a3810bd1ed134f4c Mon Sep 17 00:00:00 2001 From: Guenter Schwann <guenter@vikingsoftware.com> Date: Thu, 16 Feb 2023 10:55:29 +0100 Subject: [PATCH 2/2] Notify the user about the default port number --- src/applications/ivstreaming/main.cpp | 1 + src/applications/mscstreaming/main.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/applications/ivstreaming/main.cpp b/src/applications/ivstreaming/main.cpp index 3609d58ffd..d69cf68550 100644 --- a/src/applications/ivstreaming/main.cpp +++ b/src/applications/ivstreaming/main.cpp @@ -42,6 +42,7 @@ int main(int argc, char *argv[]) quint16 port = portString.toUShort(); if (port <= 1000) { port = 34633; + qDebug() << "Using default port" << port; } iv::IVStreamingWindow window; diff --git a/src/applications/mscstreaming/main.cpp b/src/applications/mscstreaming/main.cpp index 335fbc5e21..8ca49a0ae8 100644 --- a/src/applications/mscstreaming/main.cpp +++ b/src/applications/mscstreaming/main.cpp @@ -23,6 +23,7 @@ #include "streamingwindow.h" #include <QApplication> +#include <QDebug> #include <QDirIterator> #include <QFontDatabase> @@ -52,6 +53,7 @@ int main(int argc, char *argv[]) quint16 port = portString.toUShort(); if (port <= 1000) { port = 34622; + qDebug() << "Using default port" << port; } msc::StreamingWindow window; -- GitLab