Skip to content

Commit

Permalink
Set/move robot start position from the context menu (#1505)
Browse files Browse the repository at this point in the history
* Fix text for read-only flags
* Add button to set robot start position under current robot pos
* Fix read-only sensors behavior
* Use QT IFW 4.3
* Delete vanished translations
* Clean the code
  • Loading branch information
IKhonakhbeeva committed May 12, 2022
1 parent 26d07fa commit eb9fb1b
Show file tree
Hide file tree
Showing 19 changed files with 110 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ private slots:
void toggleDetailsVisibility();

void returnToStartMarker();
void setStartMarker();

void trainingModeChanged(bool enabled);

Expand Down
34 changes: 4 additions & 30 deletions plugins/robots/common/twoDModel/src/engine/items/imageItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ void ImageItem::setBackgroundRole(bool background)
{
mBackgroundRole = background;
if (!isSelected()) {
setEditable(!mBackgroundRole);
setFlag(ItemIsSelectable, !mBackgroundRole);
}
setZValue(background ? ZValue::Background : ZValue::Picture);
Expand All @@ -190,56 +191,29 @@ QVariant ImageItem::itemChange(QGraphicsItem::GraphicsItemChange change, const Q
emit selectedChanged(value.toBool());
if (!value.toBool() && isBackground()) {
setFlag(ItemIsSelectable, false);
setEditable(false);
unsetCursor();
}
}

return AbstractItem::itemChange(change, value);
}

void ImageItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
void ImageItem::updateCursor(QGraphicsSceneHoverEvent *event)
{
if (isSelected() || !isBackground()) {
if (resizeArea().contains(event->pos())) {
setCursor(getResizeCursor());
} else {
unsetCursor();
}
// TODO: Why not AstractItem::hoverMoveEvent()
QGraphicsItem::hoverMoveEvent(event);
}
}

void ImageItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (isSelected() || !isBackground()) {
AbstractItem::mousePressEvent(event);
} else {
event->accept();
}
}

void ImageItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (isSelected() || !isBackground()) {
AbstractItem::mouseMoveEvent(event);
} else {
event->accept();
}
}

void ImageItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (isSelected() || !isBackground()) {
AbstractItem::mouseReleaseEvent(event);
} else {
event->accept();
}
}

void ImageItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
if (isBackground()) {
setEditable(true);
setFlag(ItemIsSelectable);
}
AbstractItem::mousePressEvent(event);
Expand Down
5 changes: 1 addition & 4 deletions plugins/robots/common/twoDModel/src/engine/items/imageItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ class ImageItem : public graphicsUtils::AbstractItem
void internalImageChanged();

protected:
void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
void updateCursor(QGraphicsSceneHoverEvent *event) override;
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ bool RobotItemPopup::attachTo(const QList<QGraphicsItem *> &items)
void RobotItemPopup::initWidget()
{
QGridLayout * const layout = new QGridLayout(this);
layout->addWidget(initFollowButton(), 0, 0);
layout->addWidget(initFollowButton(), 0, 0, Qt::AlignCenter);
layout->addWidget(initReturnButton(), 0, 1);
layout->addWidget(initSpinBox(), 1, 0, 1, 2);
layout->addWidget(initSpinBox(), 1, 0);
layout->addWidget(initSetStartButton(), 1, 1);

updateDueToLayout();
}
Expand All @@ -84,6 +85,13 @@ QWidget *RobotItemPopup::initReturnButton()
return mReturnButton;
}

QWidget *RobotItemPopup::initSetStartButton()
{
mSetStartButton = initButton(":/icons/2d_target.png", tr("Move start position here"));
connect(mSetStartButton, &QAbstractButton::clicked, this, &RobotItemPopup::setRobotPositionClicked);
return mSetStartButton;
}

QAbstractButton *RobotItemPopup::initButton(const QString &icon, const QString &toolTip)
{
QPushButton * const result = new QPushButton(QIcon(icon), QString(), this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class RobotItemPopup : public graphicsUtils::ItemPopup
/// Emitted when user clicked restore robot position button.
void restoreRobotPositionClicked();

/// Emitted when user clicked set robot position here button.
void setRobotPositionClicked();

private:
bool suits(QGraphicsItem *item) override;
bool attachTo(QGraphicsItem *item) override;
Expand All @@ -51,10 +54,12 @@ class RobotItemPopup : public graphicsUtils::ItemPopup
QWidget *initReturnButton();
QAbstractButton *initButton(const QString &icon, const QString &toolTip);
QWidget *initSpinBox();
QWidget *initSetStartButton();

QAbstractButton *mFollowButton {}; // Takes ownership
QAbstractButton *mReturnButton {}; // Takes ownership
QSpinBox *mSpinBox {}; // Takes ownership
QAbstractButton *mSetStartButton {}; // Takes ownership
RobotItem *mCurrentItem {}; // Does not take ownership
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,9 @@ void TwoDModelScene::pasteItemsFromClipboard()
mController->execute(command);

for (auto &&id : newIds) {
findItem(id)->setSelected(true);
findItem(id)->setPos(findItem(id)->pos() + QPointF(20, 20));
const auto & item = findItem(id);
item->setSelected(true);
item->moveBy(20, 20);
findItem(id)->savePos();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "src/engine/items/ellipseItem.h"
#include "src/engine/items/stylusItem.h"
#include "src/engine/items/imageItem.h"
#include "src/engine/items/startPosition.h"
#include "src/engine/commands/changePropertyCommand.h"
#include "src/engine/commands/loadWorldCommand.h"

Expand Down Expand Up @@ -336,6 +337,7 @@ void TwoDModelWidget::connectUiButtons()
, this, &TwoDModelWidget::onMultiselectionCursorActionTriggered);

connect(mRobotItemPopup, &RobotItemPopup::restoreRobotPositionClicked, this, &TwoDModelWidget::returnToStartMarker);
connect(mRobotItemPopup, &RobotItemPopup::setRobotPositionClicked, this, &TwoDModelWidget::setStartMarker);
connect(mUi->initialStateButton, &QAbstractButton::clicked, this, &TwoDModelWidget::returnToStartMarker);
connect(mUi->toggleDetailsButton, &QAbstractButton::clicked, this, &TwoDModelWidget::toggleDetailsVisibility);

Expand Down Expand Up @@ -401,6 +403,13 @@ void TwoDModelWidget::returnToStartMarker()
saveWorldModelToRepo();
}

void TwoDModelWidget::setStartMarker()
{
for (auto &&model : mModel.robotModels()) {
model->startPositionMarker()->setPos(model->robotCenter());
model->startPositionMarker()->setRotation(mScene->robot(*model)->rotation());
}
}
void TwoDModelWidget::trainingModeChanged(bool enabled)
{
mUi->trainingModeButton->setToolTip(enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#pragma once

#include <kitBase/devicesConfigurationProvider.h>
#include <qrgui/plugins/toolPluginInterface/usedInterfaces/graphicalModelAssistInterface.h>
#include <qrgui/plugins/toolPluginInterface/usedInterfaces/errorReporterInterface.h>

#include "blocksTable.h"
Expand All @@ -36,6 +35,7 @@ class Autoconfigurer : public kitBase::DevicesConfigurationProvider
/// @param blocksTable - contains "code-behind" objects for blocks.
/// @param errorReporter - error reporter to report errors to.
Autoconfigurer(const qReal::GraphicalModelAssistInterface &graphicalModelApi
, const qReal::LogicalModelAssistInterface &logicalModelApi
, BlocksTable &blocksTable
, qReal::ErrorReporterInterface &errorReporter);

Expand All @@ -46,6 +46,7 @@ class Autoconfigurer : public kitBase::DevicesConfigurationProvider

private:
const qReal::GraphicalModelAssistInterface &mGraphicalModelApi;
const qReal::LogicalModelAssistInterface &mLogicalModelApi;
BlocksTable &mBlocksTable;
qReal::ErrorReporterInterface &mErrorReporter;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ BlockInterpreter::BlockInterpreter(const GraphicalModelAssistInterface &graphica
, mState(idle)
, mRobotModelManager(robotModelManager)
, mBlocksTable(new details::BlocksTable(blocksFactoryManager, robotModelManager))
, mAutoconfigurer(mGraphicalModelApi, *mBlocksTable, *mInterpretersInterface.errorReporter())
, mAutoconfigurer(mGraphicalModelApi, mLogicalModelApi, *mBlocksTable, *mInterpretersInterface.errorReporter())
, mLanguageToolbox(languageToolbox)
{
// Other components may want to subscribe to allDevicesConfigured() signal because
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ using namespace qReal;
using namespace kitBase::robotModel;

Autoconfigurer::Autoconfigurer(const GraphicalModelAssistInterface &graphicalModelApi
, const LogicalModelAssistInterface &logicalModelApi
, BlocksTable &blocksTable
, qReal::ErrorReporterInterface &errorReporter)
: mGraphicalModelApi(graphicalModelApi)
, mLogicalModelApi(logicalModelApi)
, mBlocksTable(blocksTable)
, mErrorReporter(errorReporter)
{
Expand All @@ -48,13 +50,17 @@ bool Autoconfigurer::configure(QList<qReal::Id> const &diagrams, const QString &
for (const PortInfo &port : usedDevices.keys()) {
const DeviceInfo device = usedDevices[port];
const DeviceInfo existingDevice = currentConfiguration(robotId, port);
if (!existingDevice.isNull() && !existingDevice.isA(device)) {
if (existingDevice.isA(device)) {
// Do nothing
} else if (!mLogicalModelApi.mutableLogicalRepoApi()
.metaInformation("twoDModelSensorsReadOnly").toBool() && existingDevice.isNull()) {
mErrorReporter.addInformation(QObject::tr("%2 has been auto configured to "\
"port %1").arg(port.name(), device.friendlyName()), child);
deviceConfigurationChanged(robotId, port, device, Reason::automaticConfiguration);
} else {
mErrorReporter.addError(QObject::tr("Sensor on port %1 does not correspond to blocks "\
"on the diagram.").arg(port.name()), child);
return false;
} else if (existingDevice.isNull()) {
/// @todo: Do it loudly, user must notice it
deviceConfigurationChanged(robotId, port, device, Reason::automaticConfiguration);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ ExerciseExportDialog::ExerciseExportDialog(QWidget *parent)
setModal(true);
setWindowTitle(tr("Select non-modifiable parts of exercize"));

mWorldReadOnlyCheckBox.reset(new QCheckBox(tr("2d model world is read only")));
mSensorsReadOnlyCheckBox.reset(new QCheckBox(tr("Sensors are read only")));
mRobotPositionReadOnlyCheckBox.reset(new QCheckBox(tr("2d model robot position is read only")));
mRobotSetupReadOnlyCheckBox.reset(new QCheckBox(tr("Motors to wheels binding is read only")));
mSimulationSettingsReadOnlyCheckBox.reset(new QCheckBox(tr("2d model simulation settings are read only")));
mWorldReadOnlyCheckBox.reset(new QCheckBox(tr("2D model world is read-only")));
mSensorsReadOnlyCheckBox.reset(new QCheckBox(tr("Sensors are read-only")));
mRobotPositionReadOnlyCheckBox.reset(new QCheckBox(tr("2D model robot position is read-only")));
mRobotSetupReadOnlyCheckBox.reset(new QCheckBox(tr("Motors to wheels binding is read-only")));
mSimulationSettingsReadOnlyCheckBox.reset(new QCheckBox(tr("2D model simulation settings are read-only")));

mWorldReadOnlyCheckBox->setChecked(qReal::SettingsManager::value("worldReadOnlyDefault").toBool());
mSensorsReadOnlyCheckBox->setChecked(qReal::SettingsManager::value("sensorsReadOnlyDefault").toBool());
Expand Down
27 changes: 16 additions & 11 deletions qrtranslations/fr/plugins/robots/interpreterCore_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,12 @@
<translation>temps</translation>
</message>
<message>
<location filename="../../../../plugins/robots/interpreters/interpreterCore/src/interpreter/details/autoconfigurer.cpp" line="+52"/>
<location filename="../../../../plugins/robots/interpreters/interpreterCore/src/interpreter/details/autoconfigurer.cpp" line="+57"/>
<source>%2 has been auto configured to port %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+4"/>
<source>Sensor on port %1 does not correspond to blocks on the diagram.</source>
<translation type="unfinished"></translation>
</message>
Expand Down Expand Up @@ -436,28 +441,28 @@
</message>
<message>
<location line="+2"/>
<source>2d model world is read only</source>
<translation>Le monde 2D ne peut pas être modifié </translation>
<source>2D model world is read-only</source>
<translation type="unfinished">Le monde 2D ne peut pas être modifié</translation>
</message>
<message>
<location line="+1"/>
<source>Sensors are read only</source>
<translation>La position et la configuration des capteurs ne peuvent pas être modifiées</translation>
<source>Sensors are read-only</source>
<translation type="unfinished">La position et la configuration des capteurs ne peuvent pas être modifiées</translation>
</message>
<message>
<location line="+1"/>
<source>2d model robot position is read only</source>
<translation>La position du début ne peut pas être modifié en 2D</translation>
<source>2D model robot position is read-only</source>
<translation type="unfinished">La position du début ne peut pas être modifié en 2D</translation>
</message>
<message>
<location line="+1"/>
<source>Motors to wheels binding is read only</source>
<translation>La correspondance des ports et des moteurs n&apos;est pas modifiable</translation>
<source>Motors to wheels binding is read-only</source>
<translation type="unfinished">La correspondance des ports et des moteurs n&apos;est pas modifiable</translation>
</message>
<message>
<location line="+1"/>
<source>2d model simulation settings are read only</source>
<translation>La configuration de simulation du modèle 2d ne peut pas être modifiée</translation>
<source>2D model simulation settings are read-only</source>
<translation type="unfinished">La configuration de simulation du modèle 2d ne peut pas être modifiée</translation>
</message>
<message>
<location line="+21"/>
Expand Down
13 changes: 9 additions & 4 deletions qrtranslations/fr/plugins/robots/twoDModel_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@
<context>
<name>twoDModel::view::RobotItemPopup</name>
<message>
<location filename="../../../../plugins/robots/common/twoDModel/src/engine/view/parts/robotItemPopup.cpp" line="+74"/>
<location filename="../../../../plugins/robots/common/twoDModel/src/engine/view/parts/robotItemPopup.cpp" line="+75"/>
<source>Camera folowing robot: %1</source>
<translation>Suivre le robot : %1</translation>
</message>
Expand All @@ -644,6 +644,11 @@
<source>Return robot to the initial position</source>
<translation>Retourner le robot à la position initiale</translation>
</message>
<message>
<location line="+7"/>
<source>Move start position here</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+18"/>
<source>Marker thickness</source>
Expand All @@ -661,7 +666,7 @@
<context>
<name>twoDModel::view::TwoDModelScene</name>
<message>
<location filename="../../../../plugins/robots/common/twoDModel/src/engine/view/scene/twoDModelScene.cpp" line="+718"/>
<location filename="../../../../plugins/robots/common/twoDModel/src/engine/view/scene/twoDModelScene.cpp" line="+719"/>
<source>Select images</source>
<translation type="unfinished"></translation>
</message>
Expand Down Expand Up @@ -694,7 +699,7 @@
<context>
<name>twoDModel::view::TwoDModelWidget</name>
<message>
<location filename="../../../../plugins/robots/common/twoDModel/src/engine/view/twoDModelWidget.cpp" line="+312"/>
<location filename="../../../../plugins/robots/common/twoDModel/src/engine/view/twoDModelWidget.cpp" line="+313"/>
<source>Warning</source>
<translation>Attention</translation>
</message>
Expand All @@ -712,7 +717,7 @@
<translation type="vanished">Annuler</translation>
</message>
<message>
<location line="+94"/>
<location line="+102"/>
<source>Training mode: solution will not be checked</source>
<translation type="unfinished"></translation>
</message>
Expand Down
2 changes: 1 addition & 1 deletion qrtranslations/fr/qrutils_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<translation>Division entière par zéro</translation>
</message>
<message>
<location filename="../../qrutils/graphicsUtils/abstractItem.cpp" line="+574"/>
<location filename="../../qrutils/graphicsUtils/abstractItem.cpp" line="+579"/>
<source>Remove</source>
<translation>Supprimer</translation>
</message>
Expand Down
Loading

0 comments on commit eb9fb1b

Please sign in to comment.