@@ -35,17 +35,19 @@ export class CalcApp extends GWebviewApp {
3535 // Populate RPM Calculator
3636 this . _calcDom . rpm = {
3737 btn : document . getElementById ( 'rpm-calc-btn' ) as HTMLElement ,
38- sfm : document . getElementById ( 'rpm-sfm ' ) ?. shadowRoot ?. getElementById ( 'control' ) as HTMLInputElement ,
38+ speed : document . getElementById ( 'rpm-speed ' ) ?. shadowRoot ?. getElementById ( 'control' ) as HTMLInputElement ,
3939 toolDia : document . getElementById ( 'rpm-tool-dia' ) ?. shadowRoot ?. getElementById ( 'control' ) as HTMLInputElement ,
4040 results : document . getElementById ( 'rpm-results' ) as HTMLSpanElement ,
4141 } ;
4242
4343 // Populate SFM Calculator
44- this . _calcDom . sfm = {
45- btn : document . getElementById ( 'sfm-calc-btn' ) as HTMLElement ,
46- rpm : document . getElementById ( 'sfm-rpm' ) ?. shadowRoot ?. getElementById ( 'control' ) as HTMLInputElement ,
47- toolDia : document . getElementById ( 'sfm-tool-dia' ) ?. shadowRoot ?. getElementById ( 'control' ) as HTMLInputElement ,
48- results : document . getElementById ( 'sfm-results' ) as HTMLSpanElement ,
44+ this . _calcDom . speed = {
45+ btn : document . getElementById ( 'speed-calc-btn' ) as HTMLElement ,
46+ rpm : document . getElementById ( 'speed-rpm' ) ?. shadowRoot ?. getElementById ( 'control' ) as HTMLInputElement ,
47+ toolDia : document
48+ . getElementById ( 'speed-tool-dia' )
49+ ?. shadowRoot ?. getElementById ( 'control' ) as HTMLInputElement ,
50+ results : document . getElementById ( 'speed-results' ) as HTMLSpanElement ,
4951 } ;
5052
5153 // Populate Feedrate Calculator
@@ -64,7 +66,7 @@ export class CalcApp extends GWebviewApp {
6466 // Populate Chipload Calculator
6567 this . _calcDom . chipLoad = {
6668 btn : document . getElementById ( 'cl-calc-btn' ) as HTMLElement ,
67- feedRate : document . getElementById ( 'cl-ipm ' ) ?. shadowRoot ?. getElementById ( 'control' ) as HTMLInputElement ,
69+ feedRate : document . getElementById ( 'cl-feedrate ' ) ?. shadowRoot ?. getElementById ( 'control' ) as HTMLInputElement ,
6870 rpm : document . getElementById ( 'cl-rpm' ) ?. shadowRoot ?. getElementById ( 'control' ) as HTMLInputElement ,
6971 numFlutes : document
7072 . getElementById ( 'cl-num-flutes' )
@@ -128,30 +130,30 @@ export class CalcApp extends GWebviewApp {
128130 switch ( target . id ) {
129131 case 'rpm-calc-btn' : {
130132 if ( this . _calcDom . rpm ) {
131- const sfm = Math . abs ( Number ( this . _calcDom . rpm . sfm . value ) ) ;
133+ const sfm = Math . abs ( Number ( this . _calcDom . rpm . speed . value ) ) ;
132134 const toolDia = Math . abs ( Number ( this . _calcDom . rpm . toolDia . value ) ) ;
133135
134- this . _calcDom . rpm . sfm . value = sfm ? sfm . toString ( ) : '' ;
136+ this . _calcDom . rpm . speed . value = sfm ? sfm . toString ( ) : '' ;
135137 this . _calcDom . rpm . toolDia . value = toolDia ? sfm . toString ( ) : '' ;
136138
137- result = this . _calcRPM ( sfm , toolDia , this . _units ) ;
139+ result = this . _calcRPM ( sfm , toolDia ) ;
138140
139141 this . _displayResults ( result , this . _calcDom . rpm ) ;
140142 }
141143 break ;
142144 }
143145
144- case 'sfm -calc-btn' : {
145- if ( this . _calcDom . sfm ) {
146- const rpm = Math . abs ( Number ( this . _calcDom . sfm . rpm . value ) ) ;
147- const toolDia = Math . abs ( Number ( this . _calcDom . sfm . toolDia . value ) ) ;
146+ case 'speed -calc-btn' : {
147+ if ( this . _calcDom . speed ) {
148+ const rpm = Math . abs ( Number ( this . _calcDom . speed . rpm . value ) ) ;
149+ const toolDia = Math . abs ( Number ( this . _calcDom . speed . toolDia . value ) ) ;
148150
149- this . _calcDom . sfm . rpm . value = rpm ? rpm . toString ( ) : '' ;
150- this . _calcDom . sfm . toolDia . value = toolDia ? toolDia . toString ( ) : '' ;
151+ this . _calcDom . speed . rpm . value = rpm ? rpm . toString ( ) : '' ;
152+ this . _calcDom . speed . toolDia . value = toolDia ? toolDia . toString ( ) : '' ;
151153
152- result = this . _calcSFM ( rpm , toolDia , this . _units ) ;
154+ result = this . _calcSFM ( rpm , toolDia ) ;
153155
154- this . _displayResults ( result , this . _calcDom . sfm ) ;
156+ this . _displayResults ( result , this . _calcDom . speed ) ;
155157 }
156158 break ;
157159 }
@@ -204,6 +206,7 @@ export class CalcApp extends GWebviewApp {
204206
205207 this . _displayResults ( result , this . _calcDom . mrr ) ;
206208 }
209+ break ;
207210 }
208211 }
209212 }
@@ -230,12 +233,63 @@ export class CalcApp extends GWebviewApp {
230233
231234 private _displayResults ( result : number | undefined , target : TCalcDom ) : void {
232235 if ( result && result !== Number . POSITIVE_INFINITY ) {
233- // Precision is 2 decimals or 5 for Chip Load
234- const precision = target === this . _calcDom . chipLoad ? 5 : 2 ;
235-
236236 if ( target ) {
237237 target . results . classList . remove ( 'error' ) ;
238- target . results . innerHTML = result . toFixed ( precision ) ;
238+
239+ // Precision is 2 decimals or 4 for Chip Load
240+ const precision = target === this . _calcDom . chipLoad ? 4 : 2 ;
241+ let units = '' ;
242+
243+ // Assign units
244+ switch ( target ) {
245+ case this . _calcDom . rpm :
246+ {
247+ units = '[RPM]' ;
248+ }
249+ break ;
250+
251+ case this . _calcDom . speed :
252+ {
253+ if ( this . _units === Units . Inch || this . _units === Units . Default ) {
254+ units = '[SFM]' ;
255+ } else {
256+ units = '[m/min]' ;
257+ }
258+ }
259+ break ;
260+
261+ case this . _calcDom . feedrate :
262+ {
263+ if ( this . _units === Units . Inch || this . _units === Units . Default ) {
264+ units = '[in/min]' ;
265+ } else {
266+ units = '[mm/min]' ;
267+ }
268+ }
269+ break ;
270+
271+ case this . _calcDom . chipLoad :
272+ {
273+ if ( this . _units === Units . Inch || this . _units === Units . Default ) {
274+ units = '[in]' ;
275+ } else {
276+ units = '[mm]' ;
277+ }
278+ }
279+ break ;
280+
281+ case this . _calcDom . mrr :
282+ {
283+ if ( this . _units === Units . Inch || this . _units === Units . Default ) {
284+ units = '[in<sup>3</sup>/min]' ;
285+ } else {
286+ result /= 100 ;
287+ units = '[cm<sup>3</sup>/min]' ;
288+ }
289+ }
290+ break ;
291+ }
292+ target . results . innerHTML = `${ result . toFixed ( precision ) } <sub>${ units } </sub>` ;
239293 }
240294 } else {
241295 // Answer is NaN or Infinity
@@ -246,16 +300,16 @@ export class CalcApp extends GWebviewApp {
246300 }
247301 }
248302
249- private _calcRPM ( sfm : number , toolDia : number , units : Units ) : number | undefined {
250- if ( units === Units . Inch || units === Units . Default ) {
303+ private _calcRPM ( sfm : number , toolDia : number ) : number | undefined {
304+ if ( this . _units === Units . Inch || this . _units === Units . Default ) {
251305 return ( sfm * 12 ) / ( Math . PI * toolDia ) ;
252306 } else {
253307 return ( sfm * 1000 ) / ( Math . PI * toolDia ) ;
254308 }
255309 }
256310
257- private _calcSFM ( rpm : number , toolDia : number , units : Units ) : number | undefined {
258- if ( units === Units . Inch || units === Units . Default ) {
311+ private _calcSFM ( rpm : number , toolDia : number ) : number | undefined {
312+ if ( this . _units === Units . Inch || this . _units === Units . Default ) {
259313 // Calculate SFM for Imperial
260314 return ( Math . PI * toolDia * rpm ) / 12 ;
261315 } else {
0 commit comments