-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathJogVelocityHandler.qml
114 lines (104 loc) · 3.92 KB
/
JogVelocityHandler.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/****************************************************************************
**
** Copyright (C) 2014 Alexander Rössler
** License: LGPL version 2.1
**
** This file is part of QtQuickVcp.
**
** All rights reserved. This program and the accompanying materials
** are made available under the terms of the GNU Lesser General Public License
** (LGPL) version 2.1 which accompanies this distribution, and is available at
** http://www.gnu.org/licenses/lgpl-2.1.html
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** Contributors:
** Alexander Rössler @ The Cool Tool GmbH <mail DOT aroessler AT gmail DOT com>
**
****************************************************************************/
import QtQuick 2.0
import Machinekit.Application 1.0
ApplicationObject {
property int axis: 0
readonly property string units: proportional ? "%" : distanceUnits + "/" + timeUnits
readonly property string distanceUnits: helper.ready ? helper.distanceUnits : "mm"
readonly property string timeUnits: helper.ready ? helper.timeUnits : "min"
readonly property double displayValue: proportional ? value : value * __timeFactor * __distanceFactor
property double value: 0
property double minimumValue: 0
property double maximumValue: 100
property bool proportional: false
property double minimumProportion: 0.0
property bool enabled: __ready
property bool synced: false
readonly property double __timeFactor: helper.ready ? helper.timeFactor : 1
readonly property double __distanceFactor: helper.ready ? helper.distanceFactor : 1
readonly property bool __ready: status.synced && settings.initialized
property bool __remoteUpdate: false
onValueChanged: {
if (__ready && !__remoteUpdate) {
var velocity = value;
if (proportional) {
velocity /= 100.0;
velocity *= maximumValue;
}
settings.setValue("axis" + axis + ".jogVelocity", velocity);
synced = false;
}
}
on__ReadyChanged: {
if (__ready) {
_update();
settings.onValuesChanged.connect(_update);
status.onConfigChanged.connect(_update);
status.onMotionChanged.connect(_update);
}
else {
settings.onValuesChanged.disconnect(_update);
status.onConfigChanged.disconnect(_update);
status.onMotionChanged.disconnect(_update);
synced = false;
}
}
onAxisChanged: {
if (__ready) {
_update();
}
}
Component.onDestruction: {
if (!settings.onValuesChanged) { // for qmlplugindump
return;
}
settings.onValuesChanged.disconnect(_update);
status.onConfigChanged.disconnect(_update);
status.onMotionChanged.disconnect(_update);
}
function _update() {
__remoteUpdate = true;
minimumValue = status.config.minVelocity;
var axisMaxVel = status.config.axis[axis].maxVelocity;
var configMaxVel = status.config.maxVelocity;
if ((axisMaxVel === undefined) || (axisMaxVel === 0) || (axisMaxVel > configMaxVel)) {
maximumValue = configMaxVel;
} else {
maximumValue = axisMaxVel;
}
minimumProportion = (minimumValue / maximumValue) * 100.0;
var tmpValue = settings.value("axis" + axis + ".jogVelocity");
tmpValue = Math.max(Math.min(tmpValue, maximumValue), minimumValue); // clamp value
if (proportional) {
tmpValue /= maximumValue;
tmpValue *= 100.0;
}
if (value !== tmpValue) {
value = tmpValue;
}
else {
synced = true;
}
__remoteUpdate = false;
}
}