-
Notifications
You must be signed in to change notification settings - Fork 676
/
Copy pathgeargen.js
111 lines (102 loc) · 3.36 KB
/
geargen.js
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
// To run:
//loadGeargen(paramsset)
var gProcessor;
OpenJsCad.AlertUserOfUncaughtExceptions();
var paramsset = {
circularPitch: 8,
pressureAngle: 20,
clearance: 0.05, // static
backlash: 0.05, // static
toothCount1: 45,
centerHoleDiameter1: 20,
profileShift: -0,
toothCount2: 50,
centerHoleDiameter2: 4,
type: 3,
resolution: 30,
stepsPerToothAngle: 3
};
function updateParams() {
var gearType = $('input[name=geartype]:checked').val();
console.log(gearType)
// typeof values: [3, 1, 2],
// initial: 3,
// captions: ["Gear 1 and Gear 2", "Gear 1 Only", "Gear 2 Only"]
if (gearType == 'external') {
paramsset.toothCount1 = $("#toothCount1").val()
paramsset.toothCount2 = $("#toothCount2").val()
paramsset.type = 3
} else if (gearType == 'rack') {
paramsset.toothCount1 = $("#toothCount1").val()
paramsset.toothCount2 = 0
paramsset.type = 3
} else if (gearType == 'internal') {
paramsset.toothCount1 = -$("#toothCount1").val()
paramsset.toothCount2 = $("#toothCount2").val()
paramsset.type = 3
} else if (gearType == 'single') {
paramsset.toothCount1 = $("#toothCount1").val()
paramsset.toothCount2 = $("#toothCount2").val()
paramsset.type = 1
}
paramsset.centerHoleDiameter1 = $("#centerHoleDiameter1").val()
paramsset.centerHoleDiameter2 = $("#centerHoleDiameter2").val()
paramsset.circularPitch = $("#circularPitch").val()
paramsset.pressureAngle = $("#pressureAngle").val()
paramsset.profileShift = $("#profileShift").val()
paramsset.resolution = $("#resolution").val()
paramsset.stepsPerToothAngle = $("#stepsPerToothAngle").val()
console.log(JSON.stringify(paramsset, null, 2))
}
function createGear() {
updateParams()
loadGeargen(paramsset)
}
function gearType(val) {
console.log(val)
if (val == 'external') {
$("#centerHoleDiameter1").parent().show();
$("#centerHoleDiameter2").parent().show();
$("#toothCount2").parent().show();
$("#gear1title").html("Gear 1");
$("#gear2title").html("Gear 2");
$("#gear2title").show();
//
} else if (val == 'rack') {
$("#centerHoleDiameter1").parent().show();
$("#centerHoleDiameter2").parent().hide();
$("#toothCount2").parent().hide();
$("#gear1title").html("Pinion");
$("#gear2title").html("");
$("#gear2title").hide();
//
} else if (val == 'internal') {
$("#centerHoleDiameter1").parent().hide();
$("#centerHoleDiameter2").parent().show();
$("#toothCount2").parent().show();
$("#gear1title").html("Gear 1 (Orbit)");
$("#gear2title").html("Gear 2 (Planet)");
$("#gear2title").show();
//
} else if (val == 'single') {
$("#centerHoleDiameter1").parent().show();
$("#centerHoleDiameter2").parent().hide();
$("#toothCount2").parent().hide();
$("#gear1title").html("Gear");
$("#gear2title").html("");
$("#gear2title").hide();
//
}
}
function loadGeargen(paramsset) {
gProcessor = new OpenJsCad.Processor(document.getElementById("viewer"));
$.get('lib/openjscad_files/gear11.jscad', function(data) {
var str = "// Involute spur gear builder jscad script. Licensed under the MIT license (http://opensource.org/licenses/mit-license.php). Copyright 2014 Dr. Rainer Hessmer\nvar paramsset="
str += JSON.stringify(paramsset, null, 2);
str += data;
updateSolid(str);
});
};
function updateSolid(data) {
gProcessor.setJsCad(data);
}