1 /* 2 * OpenSCAD (www.openscad.org) 3 * Copyright (C) 2009-2015 Clifford Wolf <clifford@clifford.at> and 4 * Marius Kintel <marius@kintel.net> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * As a special exception, you have permission to link this program 12 * with the CGAL library and distribute executables, as long as you 13 * follow the requirements of the GNU GPL in regard to all of the 14 * software in the executable aside from CGAL. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with this program; if not, write to the Free Software 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 * 25 */ 26 #pragma once 27 28 #include <QTimer> 29 #include <QObject> 30 31 #include "input/InputDriver.h" 32 33 class InputEventMapper : public QObject, public InputEventHandler 34 { 35 Q_OBJECT 36 37 private: 38 const static int max_axis = 9; 39 const static int max_buttons = 16; 40 41 QTimer *timer; 42 double axisRawValue[max_axis]; 43 double axisTrimValue[max_axis]; 44 double axisDeadzone[max_axis]; 45 QString actions[max_buttons]; 46 int translate[6]; 47 int rotate[6]; 48 int zoom; 49 int zoom2; 50 volatile bool stopRequest; 51 52 double scale(double val); 53 double getAxisValue(int config); 54 int parseSettingValue(const std::string val); 55 bool generateDeferredEvents(); 56 void considerGeneratingDeferredEvents(); 57 bool button_state[max_buttons]; 58 bool button_state_last[max_buttons]; 59 60 static InputEventMapper *self; 61 62 double translationGain; 63 double translationVPRelGain; 64 double rotateGain; 65 double rotateVPRelGain; 66 double zoomGain; 67 68 public: 69 InputEventMapper(); 70 virtual ~InputEventMapper(); 71 72 void stop(); 73 74 void onAxisChanged(class InputEventAxisChanged *event) override; 75 void onButtonChanged(class InputEventButtonChanged *event) override; 76 77 void onTranslateEvent(class InputEventTranslate *event) override; 78 void onRotateEvent(class InputEventRotate *event) override; 79 void onRotate2Event(class InputEventRotate2 *event) override; 80 void onActionEvent(class InputEventAction *event) override; 81 void onZoomEvent(class InputEventZoom *event) override; 82 83 void onInputMappingUpdated(); 84 void onInputCalibrationUpdated(); 85 void onInputGainUpdated(); 86 87 void onAxisAutoTrim(); 88 void onAxisTrimReset(); 89 90 static InputEventMapper * instance(); 91 static int getMaxButtons(); 92 static int getMaxAxis(); 93 94 private slots: 95 void onTimer(); 96 }; 97