Skip to content

Commit e3c30e7

Browse files
committed
Gui: [skip ci] support to remap motion data array of space mouse
1 parent da7f105 commit e3c30e7

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/Gui/GuiApplicationNativeEventAware.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
***************************************************************************/
2222

2323
#include "PreCompiled.h"
24+
#include <algorithm>
25+
#include <iomanip>
26+
#include <sstream>
2427

2528
#include <QGlobalStatic>
2629
#include <QMainWindow>
@@ -154,6 +157,29 @@ void Gui::GUIApplicationNativeEventAware::importSettings(std::vector<int>& motio
154157
{
155158
ParameterGrp::handle group = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->GetGroup("Spaceball")->GetGroup("Motion");
156159

160+
// Remapping of motion data
161+
long remap = group->GetInt("Remapping", 12345);
162+
if (remap != 12345) {
163+
std::stringstream s;
164+
s << std::setfill('0') << std::setw(6) << remap;
165+
166+
std::string str;
167+
s >> str;
168+
169+
// the string must have a length of 6 and it must contain all digits 0,...,5
170+
std::string::size_type pos1 = str.find_first_not_of("012345");
171+
std::string::size_type pos2 = std::string("012345").find_first_not_of(str);
172+
if (pos1 == std::string::npos && pos2 == std::string::npos) {
173+
std::vector<int> vec(str.size());
174+
std::transform(str.begin(), str.end(), vec.begin(), [](char c) -> int { return c - '0';});
175+
176+
std::vector<int> copy = motionDataArray;
177+
for (int i=0; i<6; i++) {
178+
motionDataArray[i] = copy[vec[i]];
179+
}
180+
}
181+
}
182+
157183
// here I import settings from a dialog. For now they are set as is
158184
bool dominant = group->GetBool("Dominant"); // Is dominant checked
159185
bool flipXY = group->GetBool("FlipYZ");; // Is Flip X/Y checked

0 commit comments

Comments
 (0)