diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2017-10-20 05:36:40 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2017-10-20 05:36:40 +0200 |
commit | 18b559ff13898e8e96275b7e329bfa23b7394f6f (patch) | |
tree | 5d22b7453992a96142c2e6a5e91289e50a377858 | |
parent | d1e7df336ce101a0fd9b05e4d3b2b8d49f6caa61 (diff) |
spline: allow switch pitch mapping max Y 90/180
-rw-r--r-- | gui/mapping-window.cpp | 42 | ||||
-rw-r--r-- | gui/mapping-window.ui | 33 | ||||
-rw-r--r-- | logic/main-settings.cpp | 3 | ||||
-rw-r--r-- | logic/mappings.cpp | 11 | ||||
-rw-r--r-- | migration/20171020_00-max-pitch-output.cpp | 70 | ||||
-rw-r--r-- | spline/spline-widget.cpp | 30 | ||||
-rw-r--r-- | spline/spline.cpp | 13 | ||||
-rw-r--r-- | spline/spline.hpp | 2 |
8 files changed, 169 insertions, 35 deletions
diff --git a/gui/mapping-window.cpp b/gui/mapping-window.cpp index 127929fe..0726186a 100644 --- a/gui/mapping-window.cpp +++ b/gui/mapping-window.cpp @@ -56,12 +56,14 @@ MapWidget::MapWidget(Mappings& m) : m(m), widgets{} tie_setting(s.a_y.altp, ui.ty_altp); tie_setting(s.a_z.altp, ui.tz_altp); - tie_setting(s.a_yaw.clamp, ui.max_yaw_rotation); - tie_setting(s.a_pitch.clamp, ui.max_pitch_rotation); - tie_setting(s.a_roll.clamp, ui.max_roll_rotation); - tie_setting(s.a_x.clamp, ui.max_x_translation); - tie_setting(s.a_y.clamp, ui.max_y_translation); - tie_setting(s.a_z.clamp, ui.max_z_translation); + tie_setting(s.a_yaw.clamp_x, ui.max_yaw_rotation); + tie_setting(s.a_pitch.clamp_x, ui.max_pitch_rotation); + tie_setting(s.a_roll.clamp_x, ui.max_roll_rotation); + tie_setting(s.a_x.clamp_x, ui.max_x_translation); + tie_setting(s.a_y.clamp_x, ui.max_y_translation); + tie_setting(s.a_z.clamp_x, ui.max_z_translation); + + tie_setting(s.a_pitch.clamp_y, ui.max_pitch_output); } void MapWidget::load() @@ -88,6 +90,9 @@ void MapWidget::load() { nullptr, Yaw, nullptr, false } }; + ui.max_pitch_output->setItemData(0, int(axis_opts::o_r180)); + ui.max_pitch_output->setItemData(1, int(axis_opts::o_r90)); + using a = axis_opts::max_clamp; for (QComboBox* x : { ui.max_yaw_rotation, ui.max_pitch_rotation, ui.max_roll_rotation }) @@ -98,6 +103,8 @@ void MapWidget::load() for (a y : { a::t30, a::t20, a::t15, a::t10, a::t100 }) x->addItem(QStringLiteral("%1 cm").arg(int(y)), y); + // XXX TODO add tie_setting overload for spline_widget!!! -sh 20171020 + for (int i = 0; qfcs[i].qfc; i++) { const bool altp = qfcs[i].altp; @@ -116,7 +123,7 @@ void MapWidget::load() qfc.force_redraw(); } - connect(&axis.opts.clamp, base_value::signal_fun<int>(), + connect(&axis.opts.clamp_x, base_value::signal_fun<int>(), &qfc, [i, &conf, &qfc](int value) { conf.set_max_input(value); qfc.reload_spline(); @@ -133,11 +140,30 @@ void MapWidget::load() // force signal to avoid duplicating the slot's logic qfc.setConfig(&conf); - axis.opts.clamp.valueChanged(axis.opts.clamp); + axis.opts.clamp_x.valueChanged(axis.opts.clamp_x); widgets[i % 6][altp ? 1 : 0] = &qfc; } + { + value<axis_opts::max_clamp>& val = s.a_pitch.clamp_y; + + Map& axis = m(Pitch); + + connect(&val, base_value::signal_fun<int>(), this, [&](int x) { + x = std::abs(x); + + spline* splines[] { &axis.spline_main, &axis.spline_alt }; + + for (spline* spl : splines) + spl->set_max_output(x); + + ui.ryconfig->setConfig(&axis.spline_main); + ui.ryconfig_alt->setConfig(&axis.spline_alt); + }); + + axis.opts.clamp_y.valueChanged(axis.opts.clamp_y); + } } void MapWidget::closeEvent(QCloseEvent*) diff --git a/gui/mapping-window.ui b/gui/mapping-window.ui index c37c4b3e..7db6f425 100644 --- a/gui/mapping-window.ui +++ b/gui/mapping-window.ui @@ -67,7 +67,7 @@ </sizepolicy> </property> <property name="text"> - <string>Max rotation</string> + <string>Max input</string> </property> </widget> </item> @@ -141,7 +141,7 @@ </sizepolicy> </property> <property name="text"> - <string>Max rotation</string> + <string>Max input</string> </property> </widget> </item> @@ -155,6 +155,27 @@ </property> </widget> </item> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Max output</string> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="max_pitch_output"> + <item> + <property name="text"> + <string>180°</string> + </property> + </item> + <item> + <property name="text"> + <string>90°</string> + </property> + </item> + </widget> + </item> </layout> </widget> </item> @@ -215,7 +236,7 @@ </sizepolicy> </property> <property name="text"> - <string>Max rotation</string> + <string>Max input</string> </property> </widget> </item> @@ -293,7 +314,7 @@ </sizepolicy> </property> <property name="text"> - <string>Max translation</string> + <string>Max input</string> </property> </widget> </item> @@ -367,7 +388,7 @@ </sizepolicy> </property> <property name="text"> - <string>Max translation</string> + <string>Max input</string> </property> </widget> </item> @@ -441,7 +462,7 @@ </sizepolicy> </property> <property name="text"> - <string>Max translation</string> + <string>Max input</string> </property> </widget> </item> diff --git a/logic/main-settings.cpp b/logic/main-settings.cpp index a706abe6..5cb6e64e 100644 --- a/logic/main-settings.cpp +++ b/logic/main-settings.cpp @@ -68,7 +68,8 @@ axis_opts::axis_opts(bundle b_settings_window, bundle b_mapping_window, QString src(b_settings_window, n(pfx, "source-index"), idx), invert(b_settings_window, n(pfx, "invert-sign"), false), altp(b_mapping_window, n(pfx, "alt-axis-sign"), false), - clamp(b_mapping_window, n(pfx, "max-value"), idx >= Yaw ? r180 : t30) + clamp_x(b_mapping_window, n(pfx, "max-value"), idx >= Yaw ? r180 : t30), + clamp_y(b_mapping_window, n(pfx, "max-output-value"), idx >= Yaw ? o_r180 : o_t75) {} QString axis_opts::n(QString pfx, QString name) diff --git a/logic/mappings.cpp b/logic/mappings.cpp index bae8c2c0..9e81bb01 100644 --- a/logic/mappings.cpp +++ b/logic/mappings.cpp @@ -1,5 +1,7 @@ #include "mappings.hpp" +#include <utility> + Map::Map(QString primary, QString secondary, int max_x, int max_y, axis_opts& opts) : opts(opts), name1(primary), @@ -7,8 +9,11 @@ Map::Map(QString primary, QString secondary, int max_x, int max_y, axis_opts& op spline_main(max_x, max_y, primary), spline_alt(max_x, max_y, secondary) { - spline_main.set_max_input(opts.clamp); - spline_alt.set_max_input(opts.clamp); + spline_main.set_max_input(max_x); + spline_alt.set_max_input(max_x); + + spline_main.set_max_output(max_y); + spline_alt.set_max_output(max_y); } void Map::save() @@ -29,7 +34,7 @@ Mappings::Mappings(std::vector<axis_opts*> opts) : Map("spline-Y", "alt-spline-Y", 100, 75, *opts[TY]), Map("spline-Z", "alt-spline-Z", 100, 75, *opts[TZ]), Map("spline-yaw", "alt-spline-yaw", 180, 180, *opts[Yaw]), - Map("spline-pitch", "alt-spline-pitch", 180, 180, *opts[Pitch]), + Map("spline-pitch", "alt-spline-pitch", 180, std::abs((int)opts[Pitch]->clamp_y), *opts[Pitch]), Map("spline-roll", "alt-spline-roll", 180, 180, *opts[Roll]) } {} diff --git a/migration/20171020_00-max-pitch-output.cpp b/migration/20171020_00-max-pitch-output.cpp new file mode 100644 index 00000000..e7ed474a --- /dev/null +++ b/migration/20171020_00-max-pitch-output.cpp @@ -0,0 +1,70 @@ +/* Copyright (c) 2017, Stanislaw Halik <sthalik@misaki.pl> + + * Permission to use, copy, modify, and/or distribute this + * software for any purpose with or without fee is hereby granted, + * provided that the above copyright notice and this permission + * notice appear in all copies. + */ + +#include "migration.hpp" +#include "options/options.hpp" +#include "logic/mappings.hpp" +#include "logic/main-settings.hpp" + +#include <QString> + +using namespace options; +using namespace migrations; + +struct max_pitch_output : migration +{ + max_pitch_output() = default; + + QString unique_date() const override + { + return "20171020_00"; + } + + QString name() const override + { + return "max pitch output in mapping window"; + } + + bool should_run() const override + { + { + static constexpr char const* name = "pitch-max-output-value"; + + bundle b = make_bundle("opentrack-mappings"); + + if (b->contains(name) && b->get<QVariant>(name) != QVariant::Invalid) + return false; + } + + main_settings s; + Mappings m { s.all_axis_opts }; + + Map& pitch_map = m(Pitch); + spline& pitch_spline_1 = pitch_map.spline_main; + spline& pitch_spline_2 = pitch_map.spline_alt; + + for (const spline& spl : { pitch_spline_1, pitch_spline_2 }) + for (QPointF& point : spl.get_points()) + if (point.y() - 1e-2 > 90) + return false; + + return true; + } + + void run() override + { + main_settings s; + axis_opts& pitch_opts = s.a_pitch; + + pitch_opts.clamp_y = axis_opts::o_r90; + + s.b_map->save(); + } +}; + +OPENTRACK_MIGRATION(max_pitch_output); diff --git a/spline/spline-widget.cpp b/spline/spline-widget.cpp index a80e08b7..2aa5e6ac 100644 --- a/spline/spline-widget.cpp +++ b/spline/spline-widget.cpp @@ -49,25 +49,23 @@ spline_widget::~spline_widget() void spline_widget::setConfig(spline* spl) { - if (spl != _config) + if (connection) { - if (connection) - { - QObject::disconnect(connection); - connection = QMetaObject::Connection(); - } + QObject::disconnect(connection); + connection = QMetaObject::Connection(); + } - if (spl) - { - std::shared_ptr<spline::settings> s = spl->get_settings(); - connection = connect(s.get(), &spline::settings::recomputed, - this, [this]() { reload_spline(); }, - Qt::QueuedConnection); - } + _config = spl; - _config = spl; - _background = QPixmap(); + if (spl) + { update_range(); + _config->ensure_valid(_config->get_points()); + + std::shared_ptr<spline::settings> s = spl->get_settings(); + connection = connect(s.get(), &spline::settings::recomputed, + this, [this]() { reload_spline(); }, + Qt::QueuedConnection); } } @@ -509,6 +507,8 @@ void spline_widget::mouseReleaseEvent(QMouseEvent *e) void spline_widget::reload_spline() { + if (_config) + _config->ensure_valid(_config->get_points()); // don't recompute here as the value's about to be recomputed in the callee update_range(); } diff --git a/spline/spline.cpp b/spline/spline.cpp index 9d783df6..f28cc98d 100644 --- a/spline/spline.cpp +++ b/spline/spline.cpp @@ -427,7 +427,18 @@ void spline::ensure_valid(const QList<QPointF>& the_points) } return false; ); - if (!overlap) + + const bool over_limit = progn( + bool ret = false; + if (pt.y() - 1e-2 > max_y) + { + pt.setY(max_y); + ret = true; + } + return ret; + ); + + if (!overlap && !over_limit) ret_list.push_back(pt); } diff --git a/spline/spline.hpp b/spline/spline.hpp index 328d1ece..cb2dc654 100644 --- a/spline/spline.hpp +++ b/spline/spline.hpp @@ -62,7 +62,7 @@ class OTR_SPLINE_EXPORT spline final MyMutex _mutex; QPointF last_input_value; - qreal max_x, max_y; + qreal max_x, max_y; // XXX TODO move to value<double> -sh 20171020 bool activep; bool validp; |