From 54c1a6f2151984985a227ee9083aecf89402fcbb Mon Sep 17 00:00:00 2001 From: Marco Randazzo Date: Sat, 25 Feb 2023 22:33:13 +0100 Subject: [PATCH] improved sliders labels alignment added a new option to set the number of decimal digits of the slider FakeMotionControl added LIMITS::Max and LIMITS::Min options --- .../master/yarpmotorgui_improved_labels.md | 12 +++++++++ .../fakeMotionControl/fakeMotionControl.cpp | 16 ++++++------ src/yarpmotorgui/jointitem.cpp | 10 +++++++ src/yarpmotorgui/jointitem.h | 2 ++ src/yarpmotorgui/mainwindow.cpp | 6 ++--- src/yarpmotorgui/mainwindow.h | 4 +-- src/yarpmotorgui/partitem.cpp | 6 +++-- src/yarpmotorgui/partitem.h | 2 +- src/yarpmotorgui/sliderOptions.cpp | 15 ++++++++--- src/yarpmotorgui/sliderOptions.h | 4 ++- src/yarpmotorgui/sliderOptions.ui | 26 +++++++++++++++++++ src/yarpmotorgui/sliderWithTarget.cpp | 26 ++++++++++++++++--- src/yarpmotorgui/sliderWithTarget.h | 1 + 13 files changed, 105 insertions(+), 25 deletions(-) create mode 100644 doc/release/master/yarpmotorgui_improved_labels.md diff --git a/doc/release/master/yarpmotorgui_improved_labels.md b/doc/release/master/yarpmotorgui_improved_labels.md new file mode 100644 index 00000000000..3d17179a31c --- /dev/null +++ b/doc/release/master/yarpmotorgui_improved_labels.md @@ -0,0 +1,12 @@ +yarpmotorgui_improved_labels {#master} +----------- + +### `yarpmotorgui` + +* improved sliders labels alignment +* added a new option to set the number of decimal digits of the slider + +### devices + +* FakeMotionControl added LIMITS::Max and LIMITS::Min options + diff --git a/src/devices/fakeMotionControl/fakeMotionControl.cpp b/src/devices/fakeMotionControl/fakeMotionControl.cpp index 487dfe2982f..fec61d95b02 100644 --- a/src/devices/fakeMotionControl/fakeMotionControl.cpp +++ b/src/devices/fakeMotionControl/fakeMotionControl.cpp @@ -1401,14 +1401,12 @@ bool FakeMotionControl::fromConfig(yarp::os::Searchable &config) */ /////// LIMITS -/* Bottle &limits=config.findGroup("LIMITS"); if (limits.isNull()) { yCWarning(FAKEMOTIONCONTROL) << "fromConfig() detected that Group LIMITS is not found in configuration file"; - return false; } - // current limit +/* // current limit if (!extractGroup(limits, xtmp, "OverloadCurrents","a list of current limits", _njoints)) return false; else @@ -1425,19 +1423,19 @@ bool FakeMotionControl::fromConfig(yarp::os::Searchable &config) return false; else for(i=1; isliderDirectPosition->resetTarget(); } +void JointItem::setNumberOfPositionSliderDecimals(size_t num) +{ + ui->sliderMixedPosition->number_of_decimals=num; + ui->sliderTrajectoryPosition->number_of_decimals = num; + ui->sliderDirectPosition->number_of_decimals = num; + ui->sliderMixedPosition->number_of_decimals = num; + ui->sliderTrajectoryPosition->number_of_decimals = num; + ui->sliderDirectPosition->number_of_decimals = num; +} + void JointItem::disablePositionSliderDouble() { if (fabs(max_position - min_position) < 1.0) diff --git a/src/yarpmotorgui/jointitem.h b/src/yarpmotorgui/jointitem.h index a4e8f3e42fb..587b3ddef78 100644 --- a/src/yarpmotorgui/jointitem.h +++ b/src/yarpmotorgui/jointitem.h @@ -81,6 +81,8 @@ class JointItem : public QWidget void sequenceActivated(); void sequenceStopped(); + void setNumberOfPositionSliderDecimals(size_t num); + void enablePositionSliderDoubleAuto(); void enablePositionSliderDoubleValue(double value); void disablePositionSliderDouble(); diff --git a/src/yarpmotorgui/mainwindow.cpp b/src/yarpmotorgui/mainwindow.cpp index 926baa1751f..8b875d0ec22 100644 --- a/src/yarpmotorgui/mainwindow.cpp +++ b/src/yarpmotorgui/mainwindow.cpp @@ -513,9 +513,9 @@ void MainWindow::onViewPositionTargetValue(bool val) emit sig_viewPositionTargetValue(val); } -void MainWindow::onSetPosSliderOptionMW(int choice, double val) +void MainWindow::onSetPosSliderOptionMW(int choice, double val, int digits) { - emit sig_setPosSliderOptionMW(choice, val); + emit sig_setPosSliderOptionMW(choice, val, digits); } void MainWindow::onSetVelSliderOptionMW(int choice, double val) { @@ -682,7 +682,7 @@ bool MainWindow::init(QStringList enabledParts, connect(this, SIGNAL(sig_viewCurrentValues(bool)), part, SLOT(onViewCurrentValues(bool))); connect(this, SIGNAL(sig_viewMotorPositions(bool)), part, SLOT(onViewMotorPositions(bool))); connect(this, SIGNAL(sig_viewDutyCycles(bool)), part, SLOT(onViewDutyCycles(bool))); - connect(this, SIGNAL(sig_setPosSliderOptionMW(int,double)), part, SLOT(onSetPosSliderOptionPI(int,double))); + connect(this, SIGNAL(sig_setPosSliderOptionMW(int,double,int)), part, SLOT(onSetPosSliderOptionPI(int,double,int))); connect(this, SIGNAL(sig_setVelSliderOptionMW(int,double)), part, SLOT(onSetVelSliderOptionPI(int,double))); connect(this, SIGNAL(sig_setTrqSliderOptionMW(int,double)), part, SLOT(onSetTrqSliderOptionPI(int,double))); connect(this, SIGNAL(sig_viewPositionTargetBox(bool)), part, SLOT(onViewPositionTargetBox(bool))); diff --git a/src/yarpmotorgui/mainwindow.h b/src/yarpmotorgui/mainwindow.h index 046a69ddefa..05c9a2b28f8 100644 --- a/src/yarpmotorgui/mainwindow.h +++ b/src/yarpmotorgui/mainwindow.h @@ -125,7 +125,7 @@ private slots: void onEnableControlPWM(bool val); void onEnableControlCurrent(bool val); void onSliderOptionsClicked(); - void onSetPosSliderOptionMW(int, double); + void onSetPosSliderOptionMW(int, double, int); void onSetVelSliderOptionMW(int, double); void onSetTrqSliderOptionMW(int, double); void onJointClicked(int partIndex, int jointIndex); @@ -142,7 +142,7 @@ private slots: void sig_viewCurrentValues(bool); void sig_viewMotorPositions(bool); void sig_viewDutyCycles(bool); - void sig_setPosSliderOptionMW(int, double); + void sig_setPosSliderOptionMW(int, double, int); void sig_setVelSliderOptionMW(int, double); void sig_setTrqSliderOptionMW(int, double); void sig_viewPositionTargetBox(bool); diff --git a/src/yarpmotorgui/partitem.cpp b/src/yarpmotorgui/partitem.cpp index 03bb57ba314..613d471d76a 100644 --- a/src/yarpmotorgui/partitem.cpp +++ b/src/yarpmotorgui/partitem.cpp @@ -249,10 +249,11 @@ PartItem::PartItem(QString robotName, int id, QString partName, ResourceFinder& int val_pos_choice = settings.value("val_pos_choice", 0).toInt(); int val_trq_choice = settings.value("val_trq_choice", 0).toInt(); int val_vel_choice = settings.value("val_vel_choice", 0).toInt(); + int num_of_pos_decimals = settings.value("num_of_pos_decimals", 3).toInt(); double val_pos_custom_step = settings.value("val_pos_custom_step", 1.0).toDouble(); double val_trq_custom_step = settings.value("val_trq_custom_step", 1.0).toDouble(); double val_vel_custom_step = settings.value("val_vel_custom_step", 1.0).toDouble(); - onSetPosSliderOptionPI(val_pos_choice, val_pos_custom_step); + onSetPosSliderOptionPI(val_pos_choice, val_pos_custom_step, num_of_pos_decimals); onSetVelSliderOptionPI(val_vel_choice, val_vel_custom_step); onSetTrqSliderOptionPI(val_trq_choice, val_trq_custom_step); onSetCurSliderOptionPI(val_trq_choice, val_trq_custom_step); @@ -2007,7 +2008,7 @@ void PartItem::onViewPositionTargetValue(bool ena) } } -void PartItem::onSetPosSliderOptionPI(int mode, double step) +void PartItem::onSetPosSliderOptionPI(int mode, double step, int numOfDec) { for (int i = 0; icount(); i++) { @@ -2028,6 +2029,7 @@ void PartItem::onSetPosSliderOptionPI(int mode, double step) { joint->disablePositionSliderDouble(); } + joint->setNumberOfPositionSliderDecimals(numOfDec); } } void PartItem::onSetVelSliderOptionPI(int mode, double step) diff --git a/src/yarpmotorgui/partitem.h b/src/yarpmotorgui/partitem.h index 2fcbc7ba27d..0210a029f8b 100644 --- a/src/yarpmotorgui/partitem.h +++ b/src/yarpmotorgui/partitem.h @@ -175,7 +175,7 @@ public slots: void onViewMotorPositions(bool); void onViewDutyCycles(bool); void onViewCurrentValues(bool); - void onSetPosSliderOptionPI(int mode, double step); + void onSetPosSliderOptionPI(int mode, double step, int numOfDec); void onSetVelSliderOptionPI(int mode, double step); void onSetTrqSliderOptionPI(int mode, double step); void onSetCurSliderOptionPI(int mode, double step); diff --git a/src/yarpmotorgui/sliderOptions.cpp b/src/yarpmotorgui/sliderOptions.cpp index 8a3a90d2cb8..ccc2bcdbf13 100644 --- a/src/yarpmotorgui/sliderOptions.cpp +++ b/src/yarpmotorgui/sliderOptions.cpp @@ -21,28 +21,32 @@ sliderOptions::sliderOptions( QWidget *parent) : val_pos_choice = settings.value("val_pos_choice", 0).toInt(); val_trq_choice = settings.value("val_trq_choice", 0).toInt(); val_vel_choice = settings.value("val_vel_choice", 0).toInt(); + val_pos_digits = settings.value("num_of_pos_decimals", 3).toInt(); val_pos_custom_step = settings.value("val_pos_custom_step", 1.0).toDouble(); val_trq_custom_step = settings.value("val_trq_custom_step", 1.0).toDouble(); val_vel_custom_step = settings.value("val_vel_custom_step", 1.0).toDouble(); val_vel_limit = settings.value("velocity_slider_limit", 100.0).toDouble(); + pos_digits_validator = new QIntValidator(this); pos_step_validator = new QDoubleValidator(this); vel_step_validator = new QDoubleValidator(this); trq_step_validator = new QDoubleValidator(this); vel_lims_validator = new QDoubleValidator(this); vel_lims_validator->setRange(0 , 100); - ui->pos_step->setValidator(vel_step_validator); + ui->pos_decimal_digits->setValidator(pos_digits_validator); + ui->pos_step->setValidator(pos_step_validator); ui->vel_step->setValidator(vel_step_validator); ui->trq_step->setValidator(trq_step_validator); ui->vel_limiter->setValidator(vel_lims_validator); + ui->pos_decimal_digits->setText(QString("%1").arg(val_pos_digits)); ui->pos_step->setText(QString("%1").arg(val_pos_custom_step)); ui->trq_step->setText(QString("%1").arg(val_trq_custom_step)); ui->vel_step->setText(QString("%1").arg(val_vel_custom_step)); ui->vel_limiter->setText(QString("%1").arg(val_vel_limit)); - connect(this, SIGNAL(sig_setPosSliderOptionSO(int, double)), parent, SLOT(onSetPosSliderOptionMW(int, double))); + connect(this, SIGNAL(sig_setPosSliderOptionSO(int, double, int)), parent, SLOT(onSetPosSliderOptionMW(int, double, int))); connect(this, SIGNAL(sig_setVelSliderOptionSO(int, double)), parent, SLOT(onSetVelSliderOptionMW(int, double))); connect(this, SIGNAL(sig_setTrqSliderOptionSO(int, double)), parent, SLOT(onSetTrqSliderOptionMW(int, double))); @@ -123,6 +127,7 @@ sliderOptions::~sliderOptions() val_vel_custom_step = ui->vel_step->text().toDouble(); val_trq_custom_step = ui->trq_step->text().toDouble(); val_vel_limit = ui->vel_limiter->text().toDouble(); + val_pos_digits = ui->pos_decimal_digits->text().toInt(); QSettings settings("YARP", "yarpmotorgui"); settings.setValue("val_pos_choice", val_pos_choice); @@ -132,13 +137,15 @@ sliderOptions::~sliderOptions() settings.setValue("val_trq_custom_step", val_trq_custom_step); settings.setValue("val_vel_custom_step", val_vel_custom_step); settings.setValue("velocity_slider_limit", val_vel_limit); - emit sig_setPosSliderOptionSO(val_pos_choice, val_pos_custom_step); + settings.setValue("num_of_pos_decimals", val_pos_digits); + emit sig_setPosSliderOptionSO(val_pos_choice, val_pos_custom_step, val_pos_digits); emit sig_setVelSliderOptionSO(val_vel_choice, val_vel_custom_step); emit sig_setTrqSliderOptionSO(val_trq_choice, val_trq_custom_step); - disconnect(this, SIGNAL(sig_setPosSliderOptionSO(int, double)), nullptr, nullptr); + disconnect(this, SIGNAL(sig_setPosSliderOptionSO(int, double, int)), nullptr, nullptr); disconnect(this, SIGNAL(sig_setVelSliderOptionSO(int, double)), nullptr, nullptr); disconnect(this, SIGNAL(sig_setTrqSliderOptionSO(int, double)), nullptr, nullptr); + delete pos_digits_validator; delete pos_step_validator; delete vel_step_validator; delete trq_step_validator; diff --git a/src/yarpmotorgui/sliderOptions.h b/src/yarpmotorgui/sliderOptions.h index d6765184b5b..5bc4eb74187 100644 --- a/src/yarpmotorgui/sliderOptions.h +++ b/src/yarpmotorgui/sliderOptions.h @@ -28,6 +28,7 @@ class sliderOptions : public QDialog private: Ui::sliderOptions *ui; + int val_pos_digits; double val_pos_custom_step; double val_vel_custom_step; double val_trq_custom_step; @@ -35,6 +36,7 @@ class sliderOptions : public QDialog int val_pos_choice; int val_vel_choice; int val_trq_choice; + QIntValidator* pos_digits_validator; QDoubleValidator* pos_step_validator; QDoubleValidator* vel_step_validator; QDoubleValidator* trq_step_validator; @@ -42,7 +44,7 @@ class sliderOptions : public QDialog signals: - void sig_setPosSliderOptionSO(int, double); + void sig_setPosSliderOptionSO(int, double, int); void sig_setVelSliderOptionSO(int, double); void sig_setTrqSliderOptionSO(int, double); }; diff --git a/src/yarpmotorgui/sliderOptions.ui b/src/yarpmotorgui/sliderOptions.ui index bec5f29f902..6fd8340cc32 100644 --- a/src/yarpmotorgui/sliderOptions.ui +++ b/src/yarpmotorgui/sliderOptions.ui @@ -107,6 +107,32 @@ + + + + 20 + 270 + 101 + 51 + + + + Number of slider decimal digits: + + + true + + + + + + 130 + 290 + 51 + 20 + + + diff --git a/src/yarpmotorgui/sliderWithTarget.cpp b/src/yarpmotorgui/sliderWithTarget.cpp index 3261ccd4b4a..ad5d3b1d9b3 100644 --- a/src/yarpmotorgui/sliderWithTarget.cpp +++ b/src/yarpmotorgui/sliderWithTarget.cpp @@ -105,14 +105,32 @@ void SliderWithTarget::paintEvent(QPaintEvent *e) { double value = this->value(); double newX = ((double)w / (double)totValues) * ((double)value + abs(this->minimum())); - sliderCurrentLabel->setGeometry(newX, -10, 40, 20); - sliderCurrentLabel->setText(QString("%L1").arg((double)value / sliderStep, 0, 'f', 3)); + QString label_text = QString("%L1").arg((double)value / sliderStep, 0, 'f', number_of_decimals); + int label_text_siz = label_text.size(); + sliderCurrentLabel->setText(label_text); + sliderCurrentLabel->setAlignment(Qt::AlignLeft); + sliderCurrentLabel->setAlignment(Qt::AlignVCenter); + //these adjustment are required to have the label properly aligned and + //to avoid overflow + double newX2 = newX; + if (newX2<0) newX2 = 0; + if (newX2>w-30) newX2 = w-30; + sliderCurrentLabel->setGeometry(newX2, -10, 60, 20); } if (enableViewTargetValue) { double newX = ((double)w / (double)totValues) * ((double)target + abs(this->minimum())); - sliderTargetLabel->setGeometry(newX, +10, 80, 20); - sliderTargetLabel->setText(QString("Ref:%L1").arg((double)target, 0, 'f', 3)); + QString label_text = QString("Ref:%L1").arg((double)target, 0, 'f', number_of_decimals); + int label_text_siz = label_text.size(); + sliderTargetLabel->setText(label_text); + sliderCurrentLabel->setAlignment(Qt::AlignLeft); + sliderCurrentLabel->setAlignment(Qt::AlignVCenter); + //these adjustment are required to have the label properly aligned and + //to avoid overflow + double newX2 = newX; + if (newX2 < 0) newX2 = 0; + if (newX2 > w - 30) newX2 = w - 30; + sliderTargetLabel->setGeometry(newX2, +10, 60, 20); } else { diff --git a/src/yarpmotorgui/sliderWithTarget.h b/src/yarpmotorgui/sliderWithTarget.h index dad2f80c7e1..8da96835b31 100644 --- a/src/yarpmotorgui/sliderWithTarget.h +++ b/src/yarpmotorgui/sliderWithTarget.h @@ -20,6 +20,7 @@ class SliderWithTarget : public QSlider bool enableViewLabel = true; bool enableViewTargetBox = true; bool enableViewTargetValue = false; + int number_of_decimals = 0; bool disableClickOutOfHandle; SliderWithTarget(QWidget * parent = 0); ~SliderWithTarget();