From 767413bb132d41ec130b5abeafb82d76f1b0a005 Mon Sep 17 00:00:00 2001 From: IKhonakhbeeva <43929571+IKhonakhbeeva@users.noreply.github.com> Date: Mon, 13 Feb 2023 12:30:43 +0500 Subject: [PATCH] Fix lost robot's position for loadWorldModel action (#1622) * Fix lost robot's position for loadWorldModel action * Fix deploy Co-authored-by: iakov --- .github/workflows/main.yml | 14 ++--- .../twoDModel/engine/view/twoDModelWidget.h | 2 + .../src/engine/view/twoDModelWidget.cpp | 57 +++++++++++++------ .../fr/plugins/robots/twoDModel_fr.ts | 8 +-- .../ru/plugins/robots/twoDModel_ru.ts | 8 +-- 5 files changed, 54 insertions(+), 35 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 68c9d3ba1a..2b07a489ea 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -69,14 +69,7 @@ jobs: run: | ARCH=32 PLATFORM=i686 - pacman --verbose --noconfirm -S msys/zlib-devel dos2unix ccache rsync unzip sshpass mingw$ARCH/mingw-w64-$PLATFORM-libzip mingw$ARCH/mingw-w64-$PLATFORM-libusb mingw$ARCH/mingw-w64-$PLATFORM-zlib mingw$ARCH/mingw-w64-$PLATFORM-pkg-config - -# https://github.com/msys2/MSYS2-packages/issues/2485 - sshpass failed with strange error - - name: Get older sshpass - run: | - wget http://repo.msys2.org/msys/x86_64/sshpass-1.06-1-x86_64.pkg.tar.xz - pacman --verbose --noconfirm -U ./sshpass-1.06-1-x86_64.pkg.tar.xz - rm ./sshpass-1.06-1-x86_64.pkg.tar.xz + pacman --verbose --noconfirm -S msys/zlib-devel dos2unix ccache rsync unzip openssh mingw$ARCH/mingw-w64-$PLATFORM-libzip mingw$ARCH/mingw-w64-$PLATFORM-libusb mingw$ARCH/mingw-w64-$PLATFORM-zlib mingw$ARCH/mingw-w64-$PLATFORM-pkg-config - name: Inject slug/short variables uses: rlespinasse/github-slug-action@v3.x @@ -230,7 +223,10 @@ jobs: - name: Deploy installer if: ${{ matrix.deploy-installer && github.event_name != 'pull_request' && github.repository_owner == 'trikset' }} - run: sshpass -p ${{ secrets.DL_PASSWORD }} rsync -ve "ssh -o StrictHostKeyChecking=no" installer/trik-studio*installer*.exe ${{ secrets.DL_USERNAME }}@${{ secrets.DL_HOST }}:~/dl/ts/fresh/installer/trik-studio-${{ env.GITHUB_REF_SLUG }}-i686-installer.exe + run: | + install -m 600 -D /dev/null ~/.ssh/id_rsa + echo "${{ secrets.DL_PRIVATE_SSH_KEY }}" > ~/.ssh/id_rsa + rsync -v --rsh="ssh -o StrictHostKeyChecking=no" installer/trik-studio*installer*.exe ${{ secrets.DL_USERNAME }}@${{ secrets.DL_HOST }}:~/dl/ts/fresh/installer/trik-studio-${{ env.GITHUB_REF_SLUG }}-i686-installer.exe - name: Prepare for RDP connection if: false #comment this line to create RDP session diff --git a/plugins/robots/common/twoDModel/include/twoDModel/engine/view/twoDModelWidget.h b/plugins/robots/common/twoDModel/include/twoDModel/engine/view/twoDModelWidget.h index 7fca4267ac..5f404eec30 100644 --- a/plugins/robots/common/twoDModel/include/twoDModel/engine/view/twoDModelWidget.h +++ b/plugins/robots/common/twoDModel/include/twoDModel/engine/view/twoDModelWidget.h @@ -234,6 +234,8 @@ private slots: void incrementTimelineCounter(); + const QDomDocument loadXmlWithConversion(const QString &loadFileName) const; + Ui::TwoDModelWidget *mUi {}; QScopedPointer mScene; QScopedPointer mActions; diff --git a/plugins/robots/common/twoDModel/src/engine/view/twoDModelWidget.cpp b/plugins/robots/common/twoDModel/src/engine/view/twoDModelWidget.cpp index d9030f10ee..e21377ec33 100644 --- a/plugins/robots/common/twoDModel/src/engine/view/twoDModelWidget.cpp +++ b/plugins/robots/common/twoDModel/src/engine/view/twoDModelWidget.cpp @@ -506,16 +506,7 @@ void TwoDModelWidget::loadWorldModel() return; } - QString errorMessage; - int errorLine = 0; - int errorColumn = 0; - const QDomDocument save = utils::xmlUtils::loadDocument(loadFileName, &errorMessage, &errorLine, &errorColumn); - if (!errorMessage.isEmpty()) { - mModel.errorReporter()->addError(QString("%1:%2: %3") - .arg(QString::number(errorLine), QString::number(errorColumn), errorMessage)); - } - - auto command = new commands::LoadWorldCommand(*this, save); + auto command = new commands::LoadWorldCommand(*this, loadXmlWithConversion(loadFileName)); if (mController) { mController->execute(command); } @@ -528,14 +519,7 @@ void TwoDModelWidget::loadWorldModelWithoutRobot() return; } - QString errorMessage; - int errorLine = 0; - int errorColumn = 0; - QDomDocument save = utils::xmlUtils::loadDocument(loadFileName, &errorMessage, &errorLine, &errorColumn); - if (!errorMessage.isEmpty()) { - mModel.errorReporter()->addError(QString("%1:%2: %3") - .arg(QString::number(errorLine), QString::number(errorColumn), errorMessage)); - } + QDomDocument save = loadXmlWithConversion(loadFileName); auto newWorld = save.firstChildElement("root"); auto oldWorld = generateWorldModelXml().firstChildElement("root"); @@ -1131,3 +1115,40 @@ void TwoDModelWidget::incrementTimelineCounter() { mUi->timelineBox->stepBy(1); } + +const QDomDocument TwoDModelWidget::loadXmlWithConversion(const QString &loadFileName) const +{ + QString errorMessage; + int errorLine = 0; + int errorColumn = 0; + const QDomDocument save = utils::xmlUtils::loadDocument(loadFileName, &errorMessage, &errorLine, &errorColumn); + if (!errorMessage.isEmpty()) { + mModel.errorReporter()->addError(QString("%1:%2: %3") + .arg(QString::number(errorLine), QString::number(errorColumn), errorMessage)); + return save; + } + + QDomElement root = save.firstChildElement("root"); + + QDomElement oldRobot = root.firstChildElement("robots").firstChildElement("robot"); + if (oldRobot.hasAttribute("position") || oldRobot.hasAttribute("direction") + || !oldRobot.firstChildElement("startPosition").isNull()) { + QDomElement world = root.firstChildElement("world"); + if (world.isNull()) { + world = root.ownerDocument().createElement("world"); + root.appendChild(world); + } + + QDomElement robot = world.ownerDocument().createElement("robot"); + robot.setAttribute("position", oldRobot.attribute("position", "0:0")); + robot.setAttribute("direction", oldRobot.attribute("direction", "0")); + robot.appendChild(oldRobot.firstChildElement("startPosition")); + world.appendChild(robot); + + oldRobot.removeAttribute("position"); + oldRobot.removeAttribute("direction"); + // start position reparented automatically + } + + return save; +} diff --git a/qrtranslations/fr/plugins/robots/twoDModel_fr.ts b/qrtranslations/fr/plugins/robots/twoDModel_fr.ts index ad74462dce..fc4e41cb10 100644 --- a/qrtranslations/fr/plugins/robots/twoDModel_fr.ts +++ b/qrtranslations/fr/plugins/robots/twoDModel_fr.ts @@ -763,22 +763,22 @@ - + 2D model saves (*.xml) Fichiers de sauvegarde du modèle 2D (*.xml) - + Loading world and robot model Chargement des modèles du monde et du robot - + Loading world without robot model - + Hide details diff --git a/qrtranslations/ru/plugins/robots/twoDModel_ru.ts b/qrtranslations/ru/plugins/robots/twoDModel_ru.ts index f4beed7293..5dfeeb7ceb 100644 --- a/qrtranslations/ru/plugins/robots/twoDModel_ru.ts +++ b/qrtranslations/ru/plugins/robots/twoDModel_ru.ts @@ -1106,17 +1106,17 @@ - + 2D model saves (*.xml) Файлы 2D модели (*.xml) - + Loading world and robot model Загрузка модели мира - + Loading world without robot model Загрузка модели мира без модели робота @@ -1133,7 +1133,7 @@ Попытка загрузить слишком большое изображение может заморозить выполнение на некоторое время. Продолжить? - + Hide details Скрыть детали