-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplay.js
More file actions
118 lines (100 loc) · 3.97 KB
/
display.js
File metadata and controls
118 lines (100 loc) · 3.97 KB
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
115
116
117
118
var form = document.querySelector("form");
const mesuree = document.getElementById("coteMesuree");
const precision = document.getElementById("precision");
const arbre = document.getElementById("arbre");
const alesage = document.getElementById("alesage");
const tour = document.getElementById("tour");
const fraiseuse = document.getElementById("fraiseuse");
const geometries = document.querySelectorAll("input[type='radio'][name='geometrie']");
function round3(number) {
return Math.round(number * 1000)/1000;
}
function sign(number) {
if (number.toString().startsWith("-") || number == 0) {
return number.toString();
} else {
return "+" + number.toString();
}
}
function checkTol(mesuree, min, max) {
const checkSpan = document.getElementById("check");
const minText = document.getElementById("minText");
const maxText = document.getElementById("maxText");
if (!min || !max) {
checkSpan.setAttribute("data-after", "");
checkSpan.classList.remove("ok");
checkSpan.classList.remove("nok");
checkSpan.removeAttribute("title");
minText.classList.remove("nok");
maxText.classList.remove("nok");
minText.removeAttribute("title");
maxText.removeAttribute("title");
} else if (mesuree >= min && mesuree <= max) {
checkSpan.setAttribute("data-after", " ✓");
checkSpan.setAttribute("title", "Cote ok");
checkSpan.classList.add("ok");
checkSpan.classList.remove("nok");
minText.classList.remove("nok");
maxText.classList.remove("nok");
} else {
checkSpan.setAttribute("data-after", " ✗");
checkSpan.setAttribute("title", "Cote hors tolérance");
checkSpan.classList.add("nok");
checkSpan.classList.remove("ok");
if (mesuree < min) {
minText.classList.add("nok");
minText.setAttribute("title", "Cote hors tolérance");
maxText.classList.remove("nok");
maxText.removeAttribute("title");
} else if (mesuree > max) {
maxText.classList.add("nok");
maxText.setAttribute("title", "Cote hors tolérance");
minText.classList.remove("nok");
minText.removeAttribute("title");
}
}
}
function changeText() {
const cotes = calcCoteMoyenne();
var corDyn = CalcCorDyn(cotes.coteMoyenne);
cotes.coteMoyenne = round3(cotes.coteMoyenne);
cotes.coteMax = round3(cotes.coteMax);
cotes.coteMin = round3(cotes.coteMin);
corDyn = round3(corDyn);
const supText = cotes.tolSup ? ` (${sign(round3(cotes.tolSup))})` : "";
const infText = cotes.tolSup ? ` (${sign(round3(cotes.tolInf))})` : "";
document.getElementById("moyenneText").innerHTML = cotes.coteMoyenne || "";
document.getElementById("maxText").innerHTML = (cotes.coteMax || "") + supText;
document.getElementById("minText").innerHTML = (cotes.coteMin || "") + infText;
document.getElementById("corDynText").innerHTML = corDyn || "";
checkTol(mesuree.value, cotes.coteMin, cotes.coteMax);
}
form.addEventListener("input", changeText);
arbre.addEventListener("input", function(){
alesage.selectedIndex = 0;
});
alesage.addEventListener("input", function(){
arbre.selectedIndex = 0;
});
tour.addEventListener("click", hideFraiseuseForm);
fraiseuse.addEventListener("click", showFraiseuseForm);
function showFraiseuseForm(checked = true) {
document.getElementById("fraiseuseOnly").hidden = false;
}
function hideFraiseuseForm() {
document.getElementById("fraiseuseOnly").hidden = true;
}
var select = document.getElementById("arbre");
for (let i = 0; i < DBarbres.length; i++) {
var opt = document.createElement("option");
opt.value = DBarbres[i];
opt.text = DBarbres[i];
select.add(opt);
}
var select = document.getElementById("alesage");
for (let i = 0; i < DBalesages.length; i++) {
var opt = document.createElement("option");
opt.value = DBalesages[i];
opt.text = DBalesages[i];
select.add(opt);
}