forked from MattStultz/extrusiongen
-
Notifications
You must be signed in to change notification settings - Fork 1
/
form_utils.js
186 lines (153 loc) · 5.83 KB
/
form_utils.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/**
* These are some helper functions that were moved from the main.html to
* keep the code simple.
*
* Requires:
* - ImageFileReader
*
* @author Ikaros Kappler
* @date 2014-03-19
* @version 1.0.0
**/
function getSelectedMeshDirection() {
return getSelectedRadioBoxValueByName( "mesh_form", "directions" );
}
// Value must be "xyz" or "zxy"
function setSelectedMeshDirection( value ) {
return setSelectedRadioBoxValueByName( "mesh_form", "directions", value );
}
function getSelectedMeshHullType() {
return getSelectedRadioBoxValueByName( "mesh_form", "mesh_hull_type" );
}
function getSelectedMeshHullStyle() {
return getSelectedRadioBoxValueByName( "mesh_form", "mesh_hull_style" );
}
// Value must be "perpendicular" or "prism"
function setSelectedMeshHullType( value ) {
return setSelectedRadioBoxValueByName( "mesh_form", "mesh_hull_type", value );
}
function getSelectedMeshParts() {
return getSelectedRadioBoxValueByName( "mesh_form", "parts" );
}
// Value must be "both" or "left" or "right"
function setSelectedMeshParts( value ) {
return setSelectedRadioBoxValueByName( "mesh_form", "parts", value );
}
function setSelectedMeshColor( value ) {
document.forms["color_form"].elements["color"].value = value;
}
function getSelectedBezierBackgroundType() {
return getSelectedRadioBoxValueByName( "bezier_background_form", "bezier_background_type" );
}
function getSelectedRadioBoxValueByName( formName, radioName ) {
if( !document.forms[formName] || !document.forms[formName].elements[radioName] )
return undefined;
var radios = document.forms[ formName ].elements[ radioName ];
for( var i = 0; i < radios.length; i++ ) {
if( radios[i].checked )
return radios[i].value;
}
return undefined;
}
function setSelectedRadioBoxValueByName( formName, radioName, value ) {
var radios = document.forms[ formName ].elements[ radioName ];
for( var i = 0; i < radios.length; i++ ) {
if( radios[i].value == value ) { //radios[i].checked )
radios[i].checked = true;
//return radios[i].value;
return true;
}
}
return false;
}
function getSelectedShapeStyle() {
//return "oval";
return getSelectedRadioBoxValueByName( "mesh_form", "shape_style" );
}
/**
* Allowed values are "circle" (DEFAULT) and "oval".
**/
function setSelectedShapeStyle( shapeStyle ) {
if( !shapeStyle )
shapeStyle = "circle";
setSelectedRadioBoxValueByName( "mesh_form", "shape_style", shapeStyle );
}
function getBendingValue( value ) {
return document.getElementById('preview_bend').value;
}
function setBendingValue( value ) {
document.getElementById('preview_bend').value = value;
displayBendingValue();
}
function displayBendingValue() {
document.getElementById('preview_bend_display').innerHTML = document.getElementById('preview_bend').value;
}
function getTwistValue( value ) {
return document.getElementById('preview_twist').value;
}
function setTwistValue( value ) {
document.getElementById('preview_twist').value = value;
displayTwistValue();
}
function displayTwistValue() {
// Sorry, the Twist setting made issues when 3D printing
//document.getElementById('preview_twist_display').innerHTML = document.getElementById('preview_twist').value;
}
function toggleFormElementsEnabled() {
document.getElementById('mesh_hull_strength').disabled = !document.getElementById('build_negative_mesh').checked;
document.getElementById('arrange_splits_on_plane').disabled = !document.getElementById('split_shape').checked;
toggleMeshDirectionEnabled();
toggleMeshHullStyleEnabled();
togglePartsEnabled();
}
function toggleMeshDirectionEnabled() {
document.getElementById('directions_xyz').disabled =
document.getElementById('directions_yxz').disabled =
( !document.getElementById('split_shape').checked ||
!document.getElementById('arrange_splits_on_plane').checked );
toggleMeshBaseEnabled();
}
function toggleMeshBaseEnabled() {
document.getElementById('mesh_hull_perpendicular').disabled =
document.getElementById('mesh_hull_prism').disabled =
( !document.getElementById('split_shape').checked ||
!document.getElementById('arrange_splits_on_plane').checked );
}
function toggleMeshHullStyleEnabled() {
if( !document.getElementById('mesh_hull_style_continuous') || document.getElementById('mesh_hull_style_discrete') )
return;
document.getElementById('mesh_hull_style_continuous').disabled =
document.getElementById('mesh_hull_style_discrete').disabled =
( !document.getElementById('split_shape').checked
//!document.getElementById('arrange_splits_on_plane').checked
);
}
function togglePartsEnabled() {
document.getElementById('parts_both').disabled =
document.getElementById('parts_left').disabled =
document.getElementById('parts_right').disabled =
( !document.getElementById('split_shape').checked );
}
/*
function getSelectedMeshBaseType() {
var radios = document.forms["mesh_form"].elements["mesh_base_type"];
for( var i = 0; i < radios.length; i++ ) {
if( radios[i].checked )
return radios[i].value;
}
return undefined;
}
*/
function changeBezierBackgroundType() {
var type = getSelectedBezierBackgroundType();
if( type == "default" ) {
bezierCanvasHandler.setCustomBackgroundImage( null,
true // redraw when ready
);
} else if( type == "file" ) {
document.forms['bezier_background_form'].elements['bezier_background_file'].click();
}
}
function loadBezierBackground() {
ImageFileReader.readBezierBackgroundImage();
}