2020-03-09 11:02:09 -04:00
/** Copyright Stewart Allen -- All Rights Reserved */
"use strict" ;
var gs _kiri _init = exports ;
( function ( ) {
if ( ! self . kiri ) self . kiri = { } ;
if ( self . kiri . init ) return ;
let KIRI = self . kiri ,
2020-04-07 21:45:21 -04:00
MOTO = self . moto ,
2020-04-09 14:52:43 -04:00
CONF = KIRI . conf ,
2020-03-09 11:02:09 -04:00
WIN = self . window ,
DOC = self . document ,
LOC = self . location ,
API = KIRI . api ,
SDB = API . sdb ,
UI = API . ui ,
UC = API . uc ,
SEED = API . const . SEED ,
LANG = API . const . LANG ,
VIEWS = API . const . VIEWS ,
MODES = API . const . MODES ,
LOCAL = API . const . LOCAL ,
SETUP = API . const . SETUP ,
DEFMODE = SETUP . dm && SETUP . dm . length === 1 ? SETUP . dm [ 0 ] : 'FDM' ,
STARTMODE = SETUP . sm && SETUP . sm . length === 1 ? SETUP . sm [ 0 ] : null ,
SPACE = KIRI . space ,
STATS = API . stats ,
2020-04-11 09:22:37 -04:00
DEG = Math . PI / 180 ,
2020-04-13 17:42:40 -04:00
ALL = [ MODES . FDM , MODES . LASER , MODES . CAM , MODES . SLA ] ,
2020-03-09 11:02:09 -04:00
CAM = [ MODES . CAM ] ,
2020-04-13 19:28:17 -04:00
SLA = [ MODES . SLA ] ,
2020-03-09 11:02:09 -04:00
FDM = [ MODES . FDM ] ,
2020-04-13 19:28:17 -04:00
FDM _SLA = [ MODES . FDM , MODES . SLA ] ,
2020-03-09 11:02:09 -04:00
FDM _CAM = [ MODES . CAM , MODES . FDM ] ,
FDM _LASER = [ MODES . LASER , MODES . FDM ] ,
2020-04-13 19:28:17 -04:00
FDM _LASER _SLA = [ MODES . LASER , MODES . FDM , MODES . SLA ] ,
2020-03-09 11:02:09 -04:00
CAM _LASER = [ MODES . LASER , MODES . CAM ] ,
2020-04-13 17:42:40 -04:00
GCODE = [ MODES . FDM , MODES . LASER , MODES . CAM ] ,
2020-04-13 19:28:17 -04:00
LASER = [ MODES . LASER ] ,
2020-03-09 11:02:09 -04:00
CATALOG = API . catalog ,
platform = API . platform ,
selection = API . selection ,
deviceLock = false ,
js2o = API . js2o ,
o2js = API . o2js ,
selectedTool = null ,
2020-03-12 11:09:29 -04:00
editTools = null ,
2020-04-22 00:24:06 -04:00
maxTool = 0 ,
platformColor ;
2020-03-09 11:02:09 -04:00
2020-03-17 16:32:43 -04:00
// extend KIRI API with local functions
API . show . devices = showDevices ;
API . device . set = selectDevice ;
2020-03-09 11:02:09 -04:00
function settings ( ) {
return API . conf . get ( ) ;
}
2020-03-16 23:57:14 -04:00
function checkSeed ( then ) {
// skip sample object load in onshape (or any script postload)
if ( ! SDB [ SEED ] ) {
SDB [ SEED ] = new Date ( ) . getTime ( ) ;
2020-03-28 16:06:22 -04:00
if ( ! SETUP . s && API . feature . seed ) {
2020-03-16 23:57:14 -04:00
platform . load _stl ( "/obj/cube.stl" , function ( vert ) {
CATALOG . putFile ( "sample cube.stl" , vert ) ;
platform . compute _max _z ( ) ;
SPACE . view . home ( ) ;
setTimeout ( API . space . save , 500 ) ;
then ( ) ;
API . help . show ( ) ;
} ) ;
return true ;
}
}
return false ;
}
function booleanSave ( ) {
2020-04-08 09:38:32 -04:00
let control = settings ( ) . controller ;
let isCompact = control . compact ;
let isDark = control . dark ;
2020-04-08 12:09:07 -04:00
control . expert = UI . expert . checked ;
2020-04-08 09:38:32 -04:00
control . showOrigin = UI . showOrigin . checked ;
control . autoLayout = UI . autoLayout . checked ;
control . freeLayout = UI . freeLayout . checked ;
control . alignTop = UI . alignTop . checked ;
control . reverseZoom = UI . reverseZoom . checked ;
control . compact = UI . compact . checked ;
control . dark = UI . dark . checked ;
SPACE . view . setZoom ( control . reverseZoom , control . zoomSpeed ) ;
2020-03-16 23:57:14 -04:00
platform . layout ( ) ;
platform . update _stock ( ) ;
API . conf . save ( ) ;
2020-03-29 20:23:48 -04:00
// if compact mode changed, reload UI
2020-04-08 09:38:32 -04:00
if ( isCompact !== control . compact ) {
2020-03-29 20:23:48 -04:00
UC . setDefaults ( isCompact ) ;
LOC . reload ( ) ;
}
2020-04-08 09:38:32 -04:00
// if dark mode changed, reload UI
if ( isDark !== control . dark ) {
LOC . reload ( ) ;
}
2020-04-17 09:43:25 -04:00
API . mode . set _expert ( control . expert ) ;
2020-03-16 23:57:14 -04:00
}
function onLayerToggle ( ) {
API . conf . update ( ) ;
API . show . slices ( ) ;
}
function onBooleanClick ( ) {
API . conf . update ( ) ;
DOC . activeElement . blur ( ) ;
}
function inputHasFocus ( ) {
let active = DOC . activeElement ;
return active && ( active . nodeName === "INPUT" || active . nodeName === "TEXTAREA" ) ;
}
function inputTextOK ( ) {
return DOC . activeElement === UI . deviceName ;
}
function textAreaHasFocus ( ) {
let active = DOC . activeElement ;
return active && active . nodeName === "TEXTAREA" ;
}
function inputSize ( ) {
return parseInt ( DOC . activeElement . size ) ;
}
function cca ( c ) {
return c . charCodeAt ( 0 ) ;
}
function keyUpHandler ( evt ) {
2020-04-12 14:35:24 -04:00
if ( API . feature . on _key ) {
if ( API . feature . on _key ( { up : evt } ) ) return ;
}
2020-03-16 23:57:14 -04:00
switch ( evt . keyCode ) {
// escape
case 27 :
// blur text input focus
DOC . activeElement . blur ( ) ;
// dismiss modals
API . modal . hide ( ) ;
// deselect widgets
platform . deselect ( ) ;
// hide all dialogs
API . dialog . hide ( ) ;
// cancel slicing
if ( KIRI . work . isSlicing ( ) ) KIRI . work . restart ( ) ;
2020-04-01 17:48:34 -04:00
// kill any poppers in compact mode
UC . hidePoppers ( ) ;
// hide layers menu
UI . layers . style . display = 'none' ;
2020-03-16 23:57:14 -04:00
break ;
}
return false ;
}
function keyDownHandler ( evt ) {
if ( API . modal . visible ( ) ) {
return false ;
}
2020-04-12 14:35:24 -04:00
if ( API . feature . on _key ) {
if ( API . feature . on _key ( { down : evt } ) ) return ;
}
2020-03-16 23:57:14 -04:00
let move = evt . altKey ? 5 : 0 ,
deg = move ? 0 : - Math . PI / ( evt . shiftKey ? 36 : 2 ) ;
switch ( evt . keyCode ) {
case 8 : // apple: delete/backspace
case 46 : // others: delete
if ( inputHasFocus ( ) ) return false ;
platform . delete ( API . selection . meshes ( ) ) ;
evt . preventDefault ( ) ;
break ;
case 37 : // left arrow
if ( inputHasFocus ( ) ) return false ;
if ( deg ) API . selection . rotate ( 0 , 0 , - deg ) ;
if ( move > 0 ) moveSelection ( - move , 0 , 0 ) ;
evt . preventDefault ( ) ;
break ;
case 39 : // right arrow
if ( inputHasFocus ( ) ) return false ;
if ( deg ) API . selection . rotate ( 0 , 0 , deg ) ;
if ( move > 0 ) moveSelection ( move , 0 , 0 ) ;
evt . preventDefault ( ) ;
break ;
case 38 : // up arrow
if ( inputHasFocus ( ) ) return false ;
if ( evt . metaKey ) return API . show . layer ( API . var . layer _at + 1 ) ;
if ( deg ) API . selection . rotate ( deg , 0 , 0 ) ;
if ( move > 0 ) moveSelection ( 0 , move , 0 ) ;
evt . preventDefault ( ) ;
break ;
case 40 : // down arrow
if ( inputHasFocus ( ) ) return false ;
if ( evt . metaKey ) return API . show . layer ( API . var . layer _at - 1 ) ;
if ( deg ) API . selection . rotate ( - deg , 0 , 0 ) ;
if ( move > 0 ) moveSelection ( 0 , - move , 0 ) ;
evt . preventDefault ( ) ;
break ;
case 65 : // 'a' for select all
if ( evt . metaKey ) {
if ( inputHasFocus ( ) ) return false ;
evt . preventDefault ( ) ;
platform . deselect ( ) ;
platform . select _all ( ) ;
}
break ;
case 83 : // 's' for save workspace
if ( evt . ctrlKey ) {
evt . preventDefault ( ) ;
API . conf . save ( ) ;
log ( "settings saved" ) ;
} else
if ( evt . metaKey ) {
evt . preventDefault ( ) ;
API . space . save ( ) ;
}
break ;
case 76 : // 'l' for restore workspace
if ( evt . metaKey ) {
evt . preventDefault ( ) ;
API . space . restore ( ) ;
}
break ;
}
}
function keyHandler ( evt ) {
let handled = true ,
current = settings ( ) ,
style , sel , i , m , bb ,
ncc = evt . charCode - 48 ;
if ( API . modal . visible ( ) || inputHasFocus ( ) ) {
return false ;
}
2020-04-12 14:35:24 -04:00
if ( API . feature . on _key ) {
if ( API . feature . on _key ( { key : evt } ) ) return ;
}
2020-03-16 23:57:14 -04:00
switch ( evt . charCode ) {
case cca ( '`' ) : API . show . slices ( 0 ) ; break ;
case cca ( '0' ) : API . show . slices ( API . var . layer _max ) ; break ;
case cca ( '1' ) : // toggle control left
if ( evt . ctrlKey ) {
style = UI . ctrlLeft . style ;
style . display = style . display === 'none' ? 'block' : 'none' ;
} else {
API . show . slices ( API . var . layer _max / 10 ) ;
}
break ;
case cca ( '2' ) : // toggle control right
if ( evt . ctrlKey ) {
style = UI . ctrlRight . style ;
style . display = style . display === 'none' ? 'block' : 'none' ;
} else {
API . show . slices ( API . var . layer _max * 2 / 10 ) ;
}
break ;
case cca ( '3' ) :
if ( evt . ctrlKey ) {
style = ! SPACE . platform . isHidden ( ) ;
SPACE . platform . setHidden ( style ) ;
SPACE . platform . showGrid ( ! style ) ;
SPACE . update ( ) ;
} else {
API . show . slices ( API . var . layer _max * 3 / 10 ) ;
}
break ;
case cca ( '4' ) : API . show . slices ( API . var . layer _max * 4 / 10 ) ; break ;
case cca ( '5' ) : API . show . slices ( API . var . layer _max * 5 / 10 ) ; break ;
case cca ( '6' ) : API . show . slices ( API . var . layer _max * 6 / 10 ) ; break ;
case cca ( '7' ) : API . show . slices ( API . var . layer _max * 7 / 10 ) ; break ;
case cca ( '8' ) : API . show . slices ( API . var . layer _max * 8 / 10 ) ; break ;
case cca ( '9' ) : API . show . slices ( API . var . layer _max * 9 / 10 ) ; break ;
case cca ( '?' ) :
API . help . show ( ) ;
break ;
case cca ( 'Z' ) : // reset stored state
if ( confirm ( 'clear all settings?' ) ) {
SDB . clear ( ) ;
}
break ;
case cca ( 'C' ) : // refresh catalog
CATALOG . refresh ( ) ;
break ;
case cca ( 'i' ) : // single settings edit
let v = prompt ( 'edit "' + current . process . processName + '"' , JSON . stringify ( current . process ) ) ;
if ( v ) {
try {
current . process = JSON . parse ( v ) ;
API . view . update _fields ( ) ;
} catch ( e ) {
console . log ( e ) ;
API . show . alert ( "invalid settings format" ) ;
}
}
break ;
case cca ( 'U' ) : // full settings url
storeSettingsToServer ( true ) ;
break ;
case cca ( 'u' ) : // full settings url
loadSettingsFromServer ( prompt ( "settings id to load" ) ) ;
break ;
case cca ( 's' ) : // complete slice
API . function . slice ( ) ;
break ;
case cca ( 'p' ) : // prepare print
2020-04-17 14:20:49 -04:00
if ( ! API . conf . isSliceSkipped ( ) ) {
2020-04-16 22:18:40 -04:00
API . function . print ( ) ;
}
2020-03-16 23:57:14 -04:00
break ;
case cca ( 'P' ) : // position widget
positionSelection ( ) ;
break ;
case cca ( 'R' ) : // position widget
rotateInputSelection ( ) ;
break ;
case cca ( 'x' ) : // export print
API . function . export ( ) ;
break ;
case cca ( 'e' ) : // devices
showDevices ( ) ;
break ;
case cca ( 'o' ) : // tools
showTools ( ) ;
break ;
case cca ( 'c' ) : // local devices
API . show . local ( ) ;
break ;
case cca ( 'v' ) : // toggle single slice view mode
UI . layerRange . checked = ! UI . layerRange . checked ;
API . show . slices ( ) ;
break ;
case cca ( 'd' ) : // duplicate object
sel = API . selection . meshes ( ) ;
platform . deselect ( ) ;
for ( i = 0 ; i < sel . length ; i ++ ) {
m = sel [ i ] . clone ( ) ;
m . geometry = m . geometry . clone ( ) ;
m . material = m . material . clone ( ) ;
bb = m . getBoundingBox ( ) ;
let nw = API . widgets . new ( ) . loadGeometry ( m . geometry ) ;
nw . move ( bb . max . x - bb . min . x + 1 , 0 , 0 ) ;
platform . add ( nw , true ) ;
}
break ;
case cca ( 'm' ) : // mirror object
API . selection . for _widgets ( function ( widget ) {
widget . mirror ( ) ;
} ) ;
SPACE . update ( ) ;
break ;
case cca ( 'R' ) : // toggle slice render mode
renderMode ++ ;
API . function . slice ( ) ;
break ;
case cca ( 'a' ) : // auto arrange items on platform
platform . layout ( ) ;
break ;
case cca ( 'w' ) : // toggle wireframe on widgets
2020-03-29 13:15:40 -04:00
API . view . wireframe ( API . color . wireframe , API . color . wireframe _opacity ) ;
2020-03-16 23:57:14 -04:00
break ;
default :
API . event . emit ( 'keypress' , evt ) ;
handled = false ;
break ;
}
if ( handled ) evt . preventDefault ( ) ;
return false ;
}
function keys ( o ) {
let key , list = [ ] ;
for ( key in o ) { if ( o . hasOwnProperty ( key ) ) list . push ( key ) }
return list . sort ( ) ;
}
function clearSelected ( children ) {
for ( let i = 0 ; i < children . length ; i ++ ) {
children [ i ] . setAttribute ( 'class' , '' ) ;
}
}
function rotateInputSelection ( ) {
if ( API . selection . meshes ( ) . length === 0 ) {
API . show . alert ( "select object to rotate" ) ;
return ;
}
let coord = prompt ( "Enter X,Y,Z degrees of rotation" ) . split ( ',' ) ,
2020-03-30 14:10:36 -04:00
prod = Math . PI / 180 ,
2020-03-16 23:57:14 -04:00
x = parseFloat ( coord [ 0 ] || 0.0 ) * prod ,
y = parseFloat ( coord [ 1 ] || 0.0 ) * prod ,
z = parseFloat ( coord [ 2 ] || 0.0 ) * prod ;
API . selection . rotate ( x , y , z ) ;
}
function positionSelection ( ) {
if ( API . selection . meshes ( ) . length === 0 ) {
API . show . alert ( "select object to position" ) ;
return ;
}
let current = settings ( ) ,
center = current . process . outputOriginCenter ,
bounds = boundsSelection ( ) ,
coord = prompt ( "Enter X,Y coordinates for selection" ) . split ( ',' ) ,
x = parseFloat ( coord [ 0 ] || 0.0 ) ,
y = parseFloat ( coord [ 1 ] || 0.0 ) ,
z = parseFloat ( coord [ 2 ] || 0.0 ) ;
if ( ! center ) {
x = x - current . device . bedWidth / 2 + ( bounds . max . x - bounds . min . x ) / 2 ;
y = y - current . device . bedDepth / 2 + ( bounds . max . y - bounds . min . y ) / 2
}
moveSelection ( x , y , z , true ) ;
}
function loadSettingsFromServer ( tok ) {
let hash = ( tok || LOC . hash . substring ( 1 ) ) . split ( "/" ) ;
if ( hash . length === 2 ) {
new moto . Ajax ( function ( reply ) {
if ( reply ) {
let res = JSON . parse ( reply ) ;
if ( res && res . ver && res . rec ) {
let set = JSON . parse ( atob ( res . rec ) ) ;
set . id = res . space ;
set . ver = res . ver ;
API . conf . put ( set ) ;
API . event . settings ( ) ;
LOC . hash = '' ;
}
}
} ) . request ( "/data/" + hash [ 0 ] + "/" + hash [ 1 ] ) ;
}
}
function storeSettingsToServer ( display ) {
let set = btoa ( JSON . stringify ( settings ( ) ) ) ;
new moto . Ajax ( function ( reply ) {
if ( reply ) {
let res = JSON . parse ( reply ) ;
if ( res && res . ver ) {
LOC . hash = res . space + "/" + res . ver ;
if ( display ) alert ( "unique settings id is: " + res . space + "/" + res . ver ) ;
}
} else {
updateSpaceState ( ) ;
}
} ) . request ( "/data/" + settings ( ) . id + "/" + settings ( ) . ver , set ) ;
}
2020-04-07 21:45:21 -04:00
function settingsExport ( ) {
if ( ! confirm ( 'Download Kiri:Moto Settings?' ) ) return ;
let json = API . conf . export ( ) ;
let blob = new Blob ( [ json ] , { type : "octet/stream" } ) ;
let url = WIN . URL . createObjectURL ( blob ) ;
$ ( 'help' ) . innerHTML = ` <a id="sexport" href=" ${ url } " download="kiriconf.b64">x</a> ` ;
$ ( 'sexport' ) . click ( ) ;
}
2020-03-16 23:57:14 -04:00
function settingsSave ( ) {
API . dialog . hide ( ) ;
let mode = API . mode . get ( ) ,
s = settings ( ) ,
def = "default" ,
cp = s . process ,
pl = s . sproc [ mode ] ,
// pt = sf[mode.toLowerCase()].p, // process field mask
name = WIN . prompt ( "Save Settings As" , cp ? cp . processName || def : def ) ;
if ( ! name ) return ;
let np = pl [ name ] = { } ;
cp . processName = name ;
for ( let k in cp ) {
if ( ! cp . hasOwnProperty ( k ) ) continue ;
// if (!pt.hasOwnProperty(k)) continue; // mask out invalid fields
np [ k ] = cp [ k ] ;
}
s . cproc [ API . mode . get ( ) ] = name ;
API . conf . save ( ) ;
API . event . settings ( ) ;
}
function settingsLoad ( ) {
API . conf . show ( ) ;
}
2020-04-09 14:52:43 -04:00
function putLocalDevice ( devicename , obj ) {
settings ( ) . devices [ devicename ] = obj ;
2020-03-16 23:57:14 -04:00
API . conf . save ( ) ;
}
function removeLocalDevice ( devicename ) {
delete settings ( ) . devices [ devicename ] ;
API . conf . save ( ) ;
}
function isLocalDevice ( devicename ) {
return settings ( ) . devices [ devicename ] ? true : false ;
}
function isFavoriteDevice ( devicename ) {
return settings ( ) . favorites [ devicename ] ? true : false ;
}
function getSelectedDevice ( ) {
return UI . deviceSelect . options [ UI . deviceSelect . selectedIndex ] . text ;
}
function selectDevice ( devicename , lock ) {
deviceLock = lock ;
if ( lock ) UI . setupDevices . style . display = 'none' ;
if ( isLocalDevice ( devicename ) ) {
setDeviceCode ( settings ( ) . devices [ devicename ] , devicename ) ;
} else {
API . ajax ( "/kiri/filter/" + API . mode . get ( ) + "/" + devicename , function ( code ) {
setDeviceCode ( code , devicename ) ;
} ) ;
}
$ ( 'selected-device' ) . innerHTML = devicename ;
}
// only for local filters
2020-04-09 14:52:43 -04:00
function cloneDevice ( ) {
let name = ` ${ getSelectedDevice ( ) } .copy ` ;
let code = API . clone ( settings ( ) . device ) ;
code . mode = API . mode . get ( ) ;
putLocalDevice ( name , code ) ;
setDeviceCode ( code , name ) ;
2020-03-16 23:57:14 -04:00
}
function setDeviceCode ( code , devicename ) {
try {
if ( typeof ( code ) === 'string' ) code = js2o ( code ) || { } ;
2020-04-18 11:34:54 -04:00
API . event . emit ( 'device.set' , devicename ) ;
2020-04-09 14:52:43 -04:00
let mode = API . mode . get ( ) ,
2020-03-16 23:57:14 -04:00
current = settings ( ) ,
2020-04-09 14:52:43 -04:00
local = isLocalDevice ( devicename ) ,
2020-03-16 23:57:14 -04:00
dproc = current . devproc [ devicename ] ,
2020-04-09 14:52:43 -04:00
dev = current . device = CONF . device _from _code ( code , mode ) ,
2020-03-16 23:57:14 -04:00
proc = current . process ;
2020-04-16 22:33:09 -04:00
dev . new = false ;
2020-04-16 18:27:28 -04:00
dev . deviceName = devicename ;
2020-04-09 14:52:43 -04:00
proc . outputOriginCenter = dev . outputOriginCenter ;
2020-03-16 23:57:14 -04:00
UI . deviceName . value = devicename ;
2020-04-08 10:38:37 -04:00
UI . deviceOrigin . checked = proc . outputOriginCenter ;
2020-04-09 14:52:43 -04:00
2020-04-10 11:53:07 -04:00
// add extruder selection buttons
if ( dev . extruders ) {
2020-04-10 15:19:47 -04:00
let ext = API . lists . extruders = [ ] ;
2020-04-10 13:24:45 -04:00
dev . internal = 0 ;
2020-04-10 11:53:07 -04:00
let selext = $ ( 'sel-ext' ) ;
selext . innerHTML = '' ;
for ( let i = dev . extruders . length - 1 ; i >= 0 ; i -- ) {
let b = DOC . createElement ( 'button' ) ;
b . appendChild ( DOC . createTextNode ( i ) ) ;
2020-04-10 13:43:02 -04:00
b . setAttribute ( 'id' , ` sel-ext- ${ i } ` ) ;
2020-04-10 11:53:07 -04:00
b . onclick = function ( ) {
API . selection . for _widgets ( w => {
current . widget [ w . id ] = { extruder : i } ;
} ) ;
2020-04-10 19:11:20 -04:00
API . platform . update _selected ( ) ;
2020-04-10 11:53:07 -04:00
} ;
selext . appendChild ( b ) ;
2020-04-10 15:19:47 -04:00
ext . push ( { id : i , name : i } ) ;
2020-04-10 11:53:07 -04:00
}
}
2020-04-09 14:52:43 -04:00
if ( mode === 'CAM' ) {
proc . camOriginTop = dev . outputOriginTop ;
}
2020-03-16 23:57:14 -04:00
// disable editing for non-local devices
[
2020-04-09 14:52:43 -04:00
UI . deviceName ,
2020-04-09 15:29:34 -04:00
UI . gcodePre ,
UI . gcodePost ,
2020-04-09 14:52:43 -04:00
UI . gcodePause ,
2020-04-09 15:29:34 -04:00
UI . bedDepth ,
UI . bedWidth ,
UI . maxHeight ,
UI . extrudeAbs ,
2020-04-09 14:52:43 -04:00
UI . deviceOrigin ,
UI . deviceOriginTop ,
UI . deviceRound ,
UI . gcodeFan ,
2020-04-09 15:29:34 -04:00
UI . gcodeTrack ,
2020-04-09 14:52:43 -04:00
UI . gcodeLayer ,
UI . extFilament ,
UI . extNozzle ,
UI . deviceMaxSpindle ,
UI . gcodeSpindle ,
UI . gcodeDwell ,
2020-04-09 15:29:34 -04:00
UI . gcodeChange ,
UI . gcodeFExt ,
UI . gcodeSpace ,
2020-04-09 14:52:43 -04:00
UI . gcodeStrip ,
UI . gcodeLaserOn ,
2020-04-10 12:40:21 -04:00
UI . gcodeLaserOff ,
UI . extPrev ,
UI . extNext ,
UI . extAdd ,
UI . extDel ,
UI . extOffsetX ,
UI . extOffsetY ,
2020-04-10 19:11:20 -04:00
UI . extSelect
2020-03-16 23:57:14 -04:00
] . forEach ( function ( e ) {
e . disabled = ! local ;
} ) ;
// hide spindle fields when device doens't support it
2020-04-09 14:52:43 -04:00
if ( mode === 'CAM' ) [
2020-04-09 15:29:34 -04:00
UI . extrudeAbs ,
2020-04-09 14:52:43 -04:00
UI . roughingSpindle ,
UI . finishingSpindle ,
UI . drillSpindle
2020-03-16 23:57:14 -04:00
] . forEach ( function ( e ) {
2020-04-09 14:52:43 -04:00
e . parentNode . style . display = dev . spindleMax >= 0 ? 'none' : 'block' ;
2020-03-16 23:57:14 -04:00
} ) ;
UI . deviceSave . disabled = ! local ;
UI . deviceDelete . disabled = ! local ;
2020-04-14 22:15:10 -04:00
UI . deviceAdd . disabled = dev . noclone ;
2020-03-16 23:57:14 -04:00
API . view . update _fields ( ) ;
platform . update _size ( ) ;
current . filter [ mode ] = devicename ;
current . cdev [ mode ] = dev ;
// restore last process associated with this device
if ( dproc ) API . conf . load ( null , dproc ) ;
API . conf . save ( ) ;
} catch ( e ) {
2020-03-17 16:32:43 -04:00
console . log ( { error : e , device : code , devicename } ) ;
API . show . alert ( ` invalid or deprecated device: " ${ devicename } " ` , 10 ) ;
API . show . alert ( ` please select a new device ` , 10 ) ;
2020-04-13 17:42:40 -04:00
throw e ;
2020-04-09 15:29:34 -04:00
showDevices ( ) ;
2020-03-16 23:57:14 -04:00
}
API . function . clear ( ) ;
API . event . settings ( ) ;
}
2020-04-16 20:39:00 -04:00
function updateDeviceName ( ) {
let newname = UI . deviceName . value ,
selected = API . device . get ( ) ,
devs = settings ( ) . devices ;
if ( newname !== selected ) {
devs [ newname ] = devs [ selected ] ;
delete devs [ selected ] ;
UI . deviceSave . onclick ( ) ;
selectDevice ( newname ) ;
}
}
2020-03-16 23:57:14 -04:00
function renderDevices ( devices ) {
UI . devices . onclick = UC . hidePop ;
UC . hidePop ( ) ;
let selectedIndex = - 1 ,
selected = API . device . get ( ) ,
devs = settings ( ) . devices ;
for ( let local in devs ) {
if ( ! ( devs . hasOwnProperty ( local ) && devs [ local ] ) ) {
continue ;
}
let dev = devs [ local ] ,
fdmCode = dev . cmd ,
fdmMode = ( API . mode . get ( ) === 'FDM' ) ;
if ( dev . mode ? ( dev . mode === API . mode . get ( ) ) : ( fdmCode ? fdmMode : ! fdmMode ) ) {
devices . push ( local ) ;
}
} ;
devices = devices . sort ( ) ;
UI . deviceClose . onclick = API . dialog . hide ;
UI . deviceSave . onclick = function ( ) {
API . function . clear ( ) ;
API . conf . save ( ) ;
showDevices ( ) ;
} ;
UI . deviceAdd . onclick = function ( ) {
API . function . clear ( ) ;
2020-04-09 14:52:43 -04:00
cloneDevice ( ) ;
2020-03-16 23:57:14 -04:00
showDevices ( ) ;
} ;
UI . deviceDelete . onclick = function ( ) {
API . function . clear ( ) ;
removeLocalDevice ( getSelectedDevice ( ) ) ;
showDevices ( ) ;
} ;
UI . deviceAll . onclick = function ( ) {
API . show . favorites ( false ) ;
showDevices ( ) ;
} ;
UI . deviceFavorites . onclick = function ( ) {
API . show . favorites ( true ) ;
showDevices ( ) ;
} ;
UI . deviceSelect . innerHTML = '' ;
let incr = 0 ;
let faves = API . show . favorites ( ) ;
let found = false ;
let first = devices [ 0 ] ;
// run through the list up to twice forcing faves off
// the second time if incr === 0 (no devices shown)
// if incr > 0, second loop is avoided
for ( let rep = 0 ; rep < 2 ; rep ++ )
if ( incr === 0 )
devices . forEach ( function ( device , index ) {
// force faves off for second try
if ( rep === 1 ) faves = false ;
let fav = isFavoriteDevice ( device ) ,
loc = isLocalDevice ( device ) ;
if ( faves && ! ( fav || loc ) ) {
return ;
}
if ( incr === 0 ) {
first = device ;
}
let opt = DOC . createElement ( 'option' ) ;
opt . appendChild ( DOC . createTextNode ( device ) ) ;
opt . onclick = function ( ) {
selectDevice ( device ) ;
} ;
opt . ondblclick = function ( ) {
if ( settings ( ) . favorites [ device ] ) {
delete settings ( ) . favorites [ device ] ;
API . show . alert ( ` removed " ${ device } " from favorites ` , 3 ) ;
} else {
settings ( ) . favorites [ device ] = true ;
API . show . alert ( ` added " ${ device } " to favorites ` , 3 ) ;
}
showDevices ( ) ;
} ;
2020-04-16 15:20:24 -04:00
if ( loc ) opt . setAttribute ( "local" , 1 ) ;
if ( loc || fav ) opt . setAttribute ( "favorite" , 1 ) ;
2020-03-16 23:57:14 -04:00
UI . deviceSelect . appendChild ( opt ) ;
if ( device === selected ) {
selectedIndex = incr ;
found = true ;
}
incr ++ ;
} ) ;
if ( selectedIndex >= 0 ) {
UI . deviceSelect . selectedIndex = selectedIndex ;
selectDevice ( selected ) ;
} else {
UI . deviceSelect . selectedIndex = 0 ;
selectDevice ( first ) ;
}
API . dialog . show ( 'devices' , true ) ;
API . dialog . update ( ) ;
UI . deviceSelect . focus ( ) ;
}
function renderTools ( ) {
UI . toolSelect . innerHTML = '' ;
maxTool = 0 ;
editTools . forEach ( function ( tool , index ) {
maxTool = Math . max ( maxTool , tool . number ) ;
tool . order = index ;
let opt = DOC . createElement ( 'option' ) ;
opt . appendChild ( DOC . createTextNode ( tool . name ) ) ;
opt . onclick = function ( ) { selectTool ( tool ) } ;
UI . toolSelect . appendChild ( opt ) ;
} ) ;
}
function selectTool ( tool ) {
selectedTool = tool ;
UI . toolName . value = tool . name ;
UI . toolNum . value = tool . number ;
UI . toolFluteDiam . value = tool . flute _diam ;
UI . toolFluteLen . value = tool . flute _len ;
UI . toolShaftDiam . value = tool . shaft _diam ;
UI . toolShaftLen . value = tool . shaft _len ;
// UI.toolTaperAngle.value = tool.taper_angle || 70;
UI . toolTaperTip . value = tool . taper _tip || 0 ;
UI . toolMetric . checked = tool . metric ;
UI . toolType . selectedIndex = [ 'endmill' , 'ballmill' , 'tapermill' ] . indexOf ( tool . type ) ;
renderTool ( tool ) ;
}
function otag ( o ) {
if ( Array . isArray ( o ) ) {
let out = [ ]
o . forEach ( oe => out . push ( otag ( oe ) ) ) ;
return out . join ( '' ) ;
}
let tags = [ ] ;
Object . keys ( o ) . forEach ( key => {
let val = o [ key ] ;
let att = [ ] ;
Object . keys ( val ) . forEach ( tk => {
let tv = val [ tk ] ;
att . push ( ` ${ tk . replace ( /_/g , '-' ) } =" ${ tv } " ` ) ;
} ) ;
tags . push ( ` < ${ key } ${ att . join ( ' ' ) } ></ ${ key } > ` ) ;
} ) ;
return tags . join ( '' ) ;
}
function renderTool ( tool ) {
let type = selectedTool . type ;
let taper = type === 'tapermill' ;
// UI.toolTaperAngle.disabled = taper ? undefined : 'true';
UI . toolTaperTip . disabled = taper ? undefined : 'true' ;
$ ( 'tool-view' ) . innerHTML = '<svg id="tool-svg" width="100%" height="100%"></svg>' ;
setTimeout ( ( ) => {
let svg = $ ( 'tool-svg' ) ;
let pad = 10 ;
let dim = { w : svg . clientWidth , h : svg . clientHeight }
let max = { w : dim . w - pad * 2 , h : dim . h - pad * 2 } ;
let off = { x : pad , y : pad } ;
let shaft _fill = "#cccccc" ;
let flute _fill = "#dddddd" ;
let stroke = "#777777" ;
let stroke _width = 3 ;
let shaft = tool . shaft _len || 1 ;
let flute = tool . flute _len || 1 ;
let tip _len = type === "ballmill" ? tool . flute _diam / 2 : 0 ;
let total _len = shaft + flute + tip _len ;
let shaft _len = ( shaft / total _len ) * max . h ;
let flute _len = ( flute / total _len ) * max . h ;
let total _wid = Math . max ( tool . flute _diam , tool . shaft _diam , total _len / 4 ) ;
let shaft _off = ( max . w * ( 1 - ( tool . shaft _diam / total _wid ) ) ) / 2 ;
let flute _off = ( max . w * ( 1 - ( tool . flute _diam / total _wid ) ) ) / 2 ;
let taper _off = ( max . w * ( 1 - ( ( tool . taper _tip || 0 ) / total _wid ) ) ) / 2 ;
let parts = [
{ rect : {
x : off . x + shaft _off , y : off . y ,
width : max . w - shaft _off * 2 , height : shaft _len ,
stroke , fill : shaft _fill , stroke _width
} }
] ;
if ( type === "tapermill" ) {
let yoff = off . y + shaft _len ;
let mid = dim . w / 2 ;
parts . push ( { path : { stroke _width , stroke , fill : flute _fill , d : [
` M ${ off . x + flute _off } ${ yoff } ` ,
` L ${ off . x + taper _off } ${ yoff + flute _len } ` ,
` L ${ dim . w - off . x - taper _off } ${ yoff + flute _len } ` ,
` L ${ dim . w - off . x - flute _off } ${ yoff } ` ,
` z `
] . join ( '\n' ) } } ) ;
} else {
parts . push ( { rect : {
x : off . x + flute _off , y : off . y + shaft _len ,
width : max . w - flute _off * 2 , height : flute _len ,
stroke , fill : flute _fill , stroke _width
} } ) ;
}
if ( type === "ballmill" ) {
let rad = ( max . w - flute _off * 2 ) / 2 ;
let xend = dim . w - off . x - flute _off ;
let yoff = off . y + shaft _len + flute _len + stroke _width / 2 ;
parts . push ( { path : { stroke _width , stroke , fill : flute _fill , d : [
` M ${ off . x + flute _off } ${ yoff } ` ,
` A ${ rad } ${ rad } 0 0 0 ${ xend } ${ yoff } ` ,
// `L ${off.x + flute_off} ${yoff}`
] . join ( '\n' ) } } )
}
svg . innerHTML = otag ( parts ) ;
} , 10 ) ;
}
function updateTool ( ) {
selectedTool . name = UI . toolName . value ;
selectedTool . number = parseInt ( UI . toolNum . value ) ;
selectedTool . flute _diam = parseFloat ( UI . toolFluteDiam . value ) ;
selectedTool . flute _len = parseFloat ( UI . toolFluteLen . value ) ;
selectedTool . shaft _diam = parseFloat ( UI . toolShaftDiam . value ) ;
selectedTool . shaft _len = parseFloat ( UI . toolShaftLen . value ) ;
// selectedTool.taper_angle = parseFloat(UI.toolTaperAngle.value);
selectedTool . taper _tip = parseFloat ( UI . toolTaperTip . value ) ;
selectedTool . metric = UI . toolMetric . checked ;
selectedTool . type = [ 'endmill' , 'ballmill' , 'tapermill' ] [ UI . toolType . selectedIndex ] ;
renderTools ( ) ;
UI . toolSelect . selectedIndex = selectedTool . order ;
setToolChanged ( true ) ;
renderTool ( selectedTool ) ;
}
function setToolChanged ( changed ) {
editTools . changed = changed ;
UI . toolsSave . disabled = ! changed ;
}
function showTools ( ) {
if ( API . mode . get _id ( ) !== MODES . CAM ) return ;
let selectedIndex = null ;
editTools = settings ( ) . tools . slice ( ) . sort ( ( a , b ) => {
return a . name > b . name ? 1 : - 1 ;
} ) ;
setToolChanged ( false ) ;
UI . toolsClose . onclick = function ( ) {
if ( editTools . changed && ! confirm ( "abandon changes?" ) ) return ;
API . dialog . hide ( ) ;
} ;
UI . toolAdd . onclick = function ( ) {
editTools . push ( {
id : Date . now ( ) ,
number : maxTool + 1 ,
name : "new" ,
type : "endmill" ,
shaft _diam : 0.25 ,
shaft _len : 1 ,
flute _diam : 0.25 ,
flute _len : 2 ,
// taper_angle: 70,
taper _tip : 0 ,
metric : false
} ) ;
setToolChanged ( true ) ;
renderTools ( ) ;
UI . toolSelect . selectedIndex = editTools . length - 1 ;
selectTool ( editTools [ editTools . length - 1 ] ) ;
} ;
UI . toolDelete . onclick = function ( ) {
editTools . remove ( selectedTool ) ;
setToolChanged ( true ) ;
renderTools ( ) ;
} ;
UI . toolsSave . onclick = function ( ) {
if ( selectedTool ) updateTool ( ) ;
settings ( ) . tools = editTools . sort ( ( a , b ) => {
return a . name < b . name ? - 1 : 1 ;
} ) ;
setToolChanged ( false ) ;
API . conf . save ( ) ;
API . view . update _fields ( ) ;
API . event . settings ( ) ;
} ;
renderTools ( ) ;
if ( editTools . length > 0 ) {
selectTool ( editTools [ 0 ] ) ;
UI . toolSelect . selectedIndex = 0 ;
} else {
UI . toolAdd . onclick ( ) ;
}
API . dialog . show ( 'tools' ) ;
UI . toolSelect . focus ( ) ;
}
function showDevices ( ) {
if ( deviceLock ) return ;
API . modal . hide ( ) ;
API . ajax ( "/api/filters-" + API . mode . get _lower ( ) , function ( flvalue ) {
if ( ! flvalue ) return ;
renderDevices ( js2o ( flvalue ) ) ;
} ) ;
}
function dragOverHandler ( evt ) {
evt . stopPropagation ( ) ;
evt . preventDefault ( ) ;
evt . dataTransfer . dropEffect = 'copy' ;
2020-04-22 00:24:06 -04:00
let oldcolor = SPACE . platform . setColor ( 0x00ff00 ) ;
if ( oldcolor !== 0x00ff00 ) platformColor = oldcolor ;
2020-03-16 23:57:14 -04:00
}
function dragLeave ( ) {
2020-04-22 00:24:06 -04:00
SPACE . platform . setColor ( platformColor ) ;
2020-03-16 23:57:14 -04:00
}
function dropHandler ( evt ) {
evt . stopPropagation ( ) ;
evt . preventDefault ( ) ;
2020-04-22 00:24:06 -04:00
SPACE . platform . setColor ( platformColor ) ;
2020-03-16 23:57:14 -04:00
let files = evt . dataTransfer . files ,
2020-04-07 19:56:30 -04:00
plate = files . length < 5 || confirm ( ` add ${ files . length } objects to workspace? ` ) ,
group = files . length < 2 ? undefined : confirm ( 'group files?' ) ? [ ] : undefined ;
2020-03-16 23:57:14 -04:00
2020-04-07 19:56:30 -04:00
if ( plate ) API . platform . load _files ( files , group ) ;
2020-03-16 23:57:14 -04:00
}
function loadCatalogFile ( e ) {
API . widgets . load ( e . target . getAttribute ( 'load' ) , function ( widget ) {
platform . add ( widget ) ;
API . dialog . hide ( ) ;
} ) ;
}
function deleteCatalogFile ( e ) {
CATALOG . deleteFile ( e . target . getAttribute ( 'del' ) ) ;
}
function updateCatalog ( files ) {
let table = UI . catalogList ,
list = [ ] ;
table . innerHTML = '' ;
for ( let name in files ) {
list . push ( { n : name , ln : name . toLowerCase ( ) , v : files [ name ] . vertices , t : files [ name ] . updated } ) ;
}
list . sort ( function ( a , b ) {
return a . ln < b . ln ? - 1 : 1 ;
} ) ;
for ( let i = 0 ; i < list . length ; i ++ ) {
let row = DOC . createElement ( 'div' ) ,
load = DOC . createElement ( 'button' ) ,
del = DOC . createElement ( 'button' ) ,
file = list [ i ] ,
name = file . n ;
load . setAttribute ( 'load' , name ) ;
load . setAttribute ( 'title' , 'file: ' + name + '\nvertices: ' + file . v ) ;
load . onclick = loadCatalogFile ;
load . appendChild ( DOC . createTextNode ( name . split ( '.' ) [ 0 ] ) ) ;
del . setAttribute ( 'del' , name ) ;
del . setAttribute ( 'title' , "remove '" + name + "'" ) ;
del . onclick = deleteCatalogFile ;
del . appendChild ( DOC . createTextNode ( 'x' ) ) ;
row . setAttribute ( "class" , "flow-row" ) ;
row . appendChild ( load ) ;
row . appendChild ( del ) ;
table . appendChild ( row ) ;
}
// fix layer scroll size
API . dialog . update ( ) ;
}
// MAIN INITIALIZATION FUNCTION
function init _one ( ) {
2020-04-20 17:50:23 -04:00
API . event . emit ( 'init.one' ) ;
2020-03-29 20:23:48 -04:00
// ensure we have settings from last session
API . conf . restore ( ) ;
2020-03-09 11:02:09 -04:00
let assets = $ ( 'assets' ) ,
control = $ ( 'control' ) ,
container = $ ( 'container' ) ,
2020-04-08 09:38:32 -04:00
welcome = $ ( 'welcome' ) ,
controller = settings ( ) . controller ,
2020-04-17 11:52:44 -04:00
compact = SETUP . compact || controller . compact ,
2020-04-08 09:38:32 -04:00
dark = controller . dark ;
2020-03-09 11:02:09 -04:00
WIN . addEventListener ( "resize" , API . dialog . update ) ;
SPACE . showSkyGrid ( false ) ;
2020-04-08 09:38:32 -04:00
SPACE . setSkyColor ( dark ? 0 : 0xffffff ) ;
2020-03-09 11:02:09 -04:00
SPACE . init ( container , function ( delta ) {
2020-03-09 18:08:08 -04:00
if ( API . var . layer _max === 0 ) return ;
2020-03-09 11:02:09 -04:00
if ( settings ( ) . controller . reverseZoom ) delta = - delta ;
2020-03-09 18:08:08 -04:00
if ( delta > 0 ) API . var . layer _at -- ;
else if ( delta < 0 ) API . var . layer _at ++ ;
2020-03-09 11:02:09 -04:00
API . show . slices ( ) ;
} ) ;
SPACE . platform . onMove ( API . conf . save ) ;
SPACE . platform . setRound ( true ) ;
2020-04-12 21:28:49 -04:00
SPACE . useDefaultKeys ( API . feature . on _key === undefined || API . feature . on _key _defaults ) ;
2020-03-09 11:02:09 -04:00
2020-04-08 09:38:32 -04:00
UC . setCompact ( compact ) ;
2020-03-29 20:23:48 -04:00
2020-03-09 11:02:09 -04:00
Object . assign ( UI , {
2020-03-16 13:11:02 -04:00
// from static HTML
2020-03-09 11:02:09 -04:00
alert : {
2020-03-16 13:11:02 -04:00
dialog : $ ( 'alert-area' ) ,
text : $ ( 'alert-text' )
2020-03-09 11:02:09 -04:00
} ,
2020-03-16 13:11:02 -04:00
container : container ,
assets : assets ,
control : control ,
ctrlLeft : $ ( 'control-left' ) ,
ctrlRight : $ ( 'control-right' ) ,
layerView : $ ( 'layer-view' ) ,
layerSlider : $ ( 'layer-slider' ) ,
modelOpacity : $ ( 'opacity' ) ,
modal : $ ( 'modal' ) ,
print : $ ( 'print' ) ,
local : $ ( 'local' ) ,
help : $ ( 'help' ) ,
devices : $ ( 'devices' ) ,
deviceAdd : $ ( 'device-add' ) ,
deviceDelete : $ ( 'device-del' ) ,
deviceSave : $ ( 'device-save' ) ,
deviceClose : $ ( 'device-close' ) ,
deviceSelect : $ ( 'device-select' ) ,
deviceFavorites : $ ( 'device-favorites' ) ,
deviceAll : $ ( 'device-all' ) ,
tools : $ ( 'tools' ) ,
toolsSave : $ ( 'tools-save' ) ,
toolsClose : $ ( 'tools-close' ) ,
toolSelect : $ ( 'tool-select' ) ,
toolAdd : $ ( 'tool-add' ) ,
toolDelete : $ ( 'tool-del' ) ,
toolType : $ ( 'tool-type' ) ,
toolName : $ ( 'tool-name' ) ,
toolNum : $ ( 'tool-num' ) ,
toolFluteDiam : $ ( 'tool-fdiam' ) ,
toolFluteLen : $ ( 'tool-flen' ) ,
toolShaftDiam : $ ( 'tool-sdiam' ) ,
toolShaftLen : $ ( 'tool-slen' ) ,
// toolTaperAngle: $('tool-tangle'),
toolTaperTip : $ ( 'tool-ttip' ) ,
toolMetric : $ ( 'tool-metric' ) ,
catalog : $ ( 'catalog' ) ,
catalogBody : $ ( 'catalogBody' ) ,
catalogList : $ ( 'catalogList' ) ,
settings : $ ( 'settings' ) ,
settingsBody : $ ( 'settingsBody' ) ,
settingsList : $ ( 'settingsList' ) ,
layerID : $ ( 'layer-id' ) ,
layerSpan : $ ( 'layer-span' ) ,
layerRange : $ ( 'layer-range' ) ,
loading : $ ( 'loading' ) . style ,
progress : $ ( 'progress' ) . style ,
prostatus : $ ( 'prostatus' ) ,
selection : $ ( 'selection' ) ,
2020-04-11 09:22:37 -04:00
sizeX : $ ( 'size_x' ) ,
sizeY : $ ( 'size_y' ) ,
sizeZ : $ ( 'size_z' ) ,
2020-03-16 13:11:02 -04:00
scaleX : $ ( 'scale_x' ) ,
scaleY : $ ( 'scale_y' ) ,
scaleZ : $ ( 'scale_z' ) ,
2020-04-11 09:22:37 -04:00
lockX : $ ( 'lock_x' ) ,
lockY : $ ( 'lock_y' ) ,
lockZ : $ ( 'lock_z' ) ,
2020-03-16 13:11:02 -04:00
stock : $ ( 'stock' ) ,
stockWidth : $ ( 'stock-width' ) ,
stockDepth : $ ( 'stock-width' ) ,
stockHeight : $ ( 'stock-width' ) ,
2020-03-16 12:11:30 -04:00
2020-04-08 10:38:37 -04:00
device : UC . newGroup ( LANG . dv _gr _dev , $ ( 'device' ) , { group : "ddev" , nocompact : true } ) ,
2020-04-16 20:39:00 -04:00
deviceName : UC . newInput ( LANG . dv _name _s , { title : LANG . dv _name _l , size : "60%" , text : true , action : updateDeviceName } ) ,
2020-04-22 10:54:46 -04:00
bedWidth : UC . newInput ( LANG . dv _bedw _s , { title : LANG . dv _bedw _l , convert : UC . toFloat , size : 6 } ) ,
bedDepth : UC . newInput ( LANG . dv _bedd _s , { title : LANG . dv _bedd _l , convert : UC . toFloat , size : 6 } ) ,
maxHeight : UC . newInput ( LANG . dv _bedh _s , { title : LANG . dv _bedh _l , convert : UC . toFloat , size : 6 , modes : FDM _SLA } ) ,
2020-04-08 10:38:37 -04:00
deviceMaxSpindle : UC . newInput ( LANG . dv _spmx _s , { title : LANG . dv _spmx _l , convert : UC . toInt , modes : CAM } ) ,
2020-04-14 22:15:10 -04:00
deviceOrigin : UC . newBoolean ( LANG . dv _orgc _s , onBooleanClick , { title : LANG . dv _orgc _l , modes : GCODE } ) ,
2020-04-08 10:38:37 -04:00
deviceOriginTop : UC . newBoolean ( LANG . dv _orgt _s , onBooleanClick , { title : LANG . dv _orgt _l , modes : CAM } ) ,
deviceRound : UC . newBoolean ( LANG . dv _bedc _s , onBooleanClick , { title : LANG . dv _bedc _l , modes : FDM } ) ,
extruder : UC . newGroup ( LANG . dv _gr _ext , $ ( 'device' ) , { group : "dext" , nocompact : true , modes : FDM } ) ,
2020-04-09 14:52:43 -04:00
extFilament : UC . newInput ( LANG . dv _fila _s , { title : LANG . dv _fila _l , convert : UC . toFloat , modes : FDM } ) ,
extNozzle : UC . newInput ( LANG . dv _nozl _s , { title : LANG . dv _nozl _l , convert : UC . toFloat , modes : FDM } ) ,
extOffsetX : UC . newInput ( LANG . dv _exox _s , { title : LANG . dv _exox _l , convert : UC . toFloat , modes : FDM , expert : true } ) ,
extOffsetY : UC . newInput ( LANG . dv _exoy _s , { title : LANG . dv _exoy _l , convert : UC . toFloat , modes : FDM , expert : true } ) ,
extSelect : UC . newText ( LANG . dv _exts _s , { title : LANG . dv _exts _l , modes : FDM , size : 14 , height : 3 , modes : FDM , expert : true } ) ,
2020-04-09 15:29:34 -04:00
extrudeAbs : UC . newBoolean ( LANG . dv _xtab _s , onBooleanClick , { title : LANG . dv _xtab _l , modes : FDM } ) ,
2020-04-09 14:52:43 -04:00
extActions : UC . newTableRow ( [ [
2020-04-10 12:27:08 -04:00
UI . extPrev = UC . newButton ( "<" ) ,
UI . extAdd = UC . newButton ( "+" ) ,
UI . extDel = UC . newButton ( "-" ) ,
UI . extNext = UC . newButton ( ">" )
2020-04-08 10:38:37 -04:00
] ] , { modes : FDM , expert : true } ) ,
2020-04-13 17:42:40 -04:00
gcode : UC . newGroup ( LANG . dv _gr _gco , $ ( 'device' ) , { group : "dgco" , nocompact : true , modes : GCODE } ) ,
2020-04-08 10:38:37 -04:00
gcodeFan : UC . newInput ( LANG . dv _fanp _s , { title : LANG . dv _fanp _l , modes : FDM , size : "40%" , text : true } ) ,
2020-04-09 15:29:34 -04:00
gcodeTrack : UC . newInput ( LANG . dv _prog _s , { title : LANG . dv _prog _l , modes : FDM , size : "40%" , text : true } ) ,
2020-04-08 10:38:37 -04:00
gcodeLayer : UC . newText ( LANG . dv _layr _s , { title : LANG . dv _layr _l , modes : FDM , size : 14 , height : 2 } ) ,
2020-04-21 20:31:14 -04:00
gcodeSpace : UC . newBoolean ( LANG . dv _tksp _s , onBooleanClick , { title : LANG . dv _tksp _l , modes : CAM _LASER } ) ,
gcodeStrip : UC . newBoolean ( LANG . dv _strc _s , onBooleanClick , { title : LANG . dv _strc _l , modes : CAM } ) ,
2020-04-09 15:29:34 -04:00
gcodeFExt : UC . newInput ( LANG . dv _fext _s , { title : LANG . dv _fext _l , modes : CAM _LASER , size : 7 , text : true } ) ,
2020-04-08 10:38:37 -04:00
gcodeDwell : UC . newText ( LANG . dv _dwll _s , { title : LANG . dv _dwll _l , modes : CAM , size : 14 , height : 2 } ) ,
2020-04-09 15:29:34 -04:00
gcodeChange : UC . newText ( LANG . dv _tool _s , { title : LANG . dv _tool _l , modes : CAM , size : 14 , height : 2 } ) ,
2020-04-08 10:38:37 -04:00
gcodeSpindle : UC . newText ( LANG . dv _sspd _s , { title : LANG . dv _sspd _l , modes : CAM , size : 14 , height : 2 } ) ,
gcodePause : UC . newText ( LANG . dv _paus _s , { title : LANG . dv _paus _l , modes : FDM , size : 14 , height : 3 } ) ,
gcodeLaserOn : UC . newText ( LANG . dv _lzon _s , { title : LANG . dv _lzon _l , modes : LASER , size : 14 , height : 3 } ) ,
gcodeLaserOff : UC . newText ( LANG . dv _lzof _s , { title : LANG . dv _lzof _l , modes : LASER , size : 14 , height : 3 } ) ,
2020-04-13 17:42:40 -04:00
gcodePre : UC . newText ( LANG . dv _head _s , { title : LANG . dv _head _l , modes : GCODE , size : 14 , height : 3 } ) ,
gcodePost : UC . newText ( LANG . dv _foot _s , { title : LANG . dv _foot _l , modes : GCODE , size : 14 , height : 3 } ) ,
2020-03-16 12:11:30 -04:00
2020-03-29 13:15:40 -04:00
mode : UC . newGroup ( LANG . mo _menu , assets , { region : "left" } ) ,
2020-03-09 11:02:09 -04:00
modeTable : UC . newTableRow ( [
[
UI . modeFDM =
2020-03-15 23:22:36 -04:00
UC . newButton ( LANG . mo _fdmp , function ( ) { API . mode . set ( 'FDM' , null , platform . update _size ) } ) ,
2020-04-13 17:42:40 -04:00
] , [
UI . modeSLA =
UC . newButton ( LANG . mo _slap , function ( ) { API . mode . set ( 'SLA' , null , platform . update _size ) } ) ,
2020-03-09 11:02:09 -04:00
] , [
UI . modeLASER =
2020-03-15 23:22:36 -04:00
UC . newButton ( LANG . mo _lazr , function ( ) { API . mode . set ( 'LASER' , null , platform . update _size ) } ) ,
2020-03-09 11:02:09 -04:00
] , [
UI . modeCAM =
2020-03-15 23:22:36 -04:00
UC . newButton ( LANG . mo _cncm , function ( ) { API . mode . set ( 'CAM' , null , platform . update _size ) } , { id : "modeCAM" } ) ,
2020-03-09 11:02:09 -04:00
]
] ) ,
2020-03-15 23:22:36 -04:00
system : UC . newGroup ( LANG . su _menu ) ,
2020-03-09 11:02:09 -04:00
sysTable : UC . newTableRow ( [
[
UI . setupDevices =
2020-03-15 23:22:36 -04:00
UC . newButton ( LANG . su _devi , showDevices )
2020-03-09 11:02:09 -04:00
] , [
UI . setupTools =
2020-03-15 23:22:36 -04:00
UC . newButton ( LANG . su _tool , showTools , { modes : CAM } )
2020-04-07 21:45:21 -04:00
] , [
UI . setupExport =
2020-04-08 10:38:37 -04:00
UC . newButton ( LANG . su _xprt , settingsExport , { modes : ALL , expert : true } )
2020-03-09 11:02:09 -04:00
] , [
UI . localButton =
2020-03-29 20:23:48 -04:00
UC . newButton ( LANG . su _locl , API . show . local , { modes : FDM _CAM , expert : true } )
2020-03-09 11:02:09 -04:00
] , [
UI . helpButton =
2020-03-15 23:22:36 -04:00
UC . newButton ( LANG . su _help , API . help . show )
2020-03-09 11:02:09 -04:00
]
] ) ,
2020-03-15 23:22:36 -04:00
wsFunc : UC . newGroup ( LANG . fn _menu ) ,
2020-03-09 11:02:09 -04:00
wsFuncTable : UC . newTableRow ( [
[
2020-03-15 20:17:14 -04:00
UI . load =
2020-03-29 20:23:48 -04:00
UC . newButton ( LANG . fn _impo , function ( ) { API . event . import ( ) } , { class : "asym" } ) ,
2020-03-09 11:02:09 -04:00
UI . import =
2020-03-29 20:23:48 -04:00
UC . newButton ( "+" , undefined , { class : "asym" } )
2020-03-09 11:02:09 -04:00
] , [
UI . modeArrange =
2020-03-15 23:22:36 -04:00
UC . newButton ( LANG . fn _arra , platform . layout ) ,
2020-03-09 11:02:09 -04:00
] , [
UI . modeSlice =
2020-03-15 23:22:36 -04:00
UC . newButton ( LANG . fn _slic , API . function . slice )
2020-03-09 11:02:09 -04:00
] , [
UI . modePreview =
2020-03-15 23:22:36 -04:00
UC . newButton ( LANG . fn _prev , API . function . print ) ,
2020-03-09 11:02:09 -04:00
] , [
UI . modeExport =
2020-03-15 23:22:36 -04:00
UC . newButton ( LANG . fn _expo , API . function . export )
2020-03-09 11:02:09 -04:00
]
] ) ,
2020-03-15 23:22:36 -04:00
camera : UC . newGroup ( LANG . vu _menu ) ,
2020-03-09 11:02:09 -04:00
camTable : UC . newTableRow ( [
[
2020-03-15 23:22:36 -04:00
UC . newButton ( LANG . vu _home , SPACE . view . home ) ,
UC . newButton ( LANG . vu _rset , SPACE . view . reset )
2020-03-09 11:02:09 -04:00
] , [
2020-03-15 23:22:36 -04:00
UC . newButton ( LANG . vu _sptp , SPACE . view . top ) ,
UC . newButton ( LANG . vu _spfr , SPACE . view . front ) ,
2020-03-09 11:02:09 -04:00
] , [
2020-03-15 23:22:36 -04:00
UC . newButton ( LANG . vu _splt , SPACE . view . left ) ,
UC . newButton ( LANG . vu _sprt , SPACE . view . right )
2020-03-09 11:02:09 -04:00
]
] ) ,
2020-04-16 23:59:13 -04:00
workspace : UC . newGroup ( LANG . ws _menu , undefined , { modes : ALL , expert : true } ) ,
2020-03-09 11:02:09 -04:00
wsTable : UC . newTableRow ( [
[
UI . saveButton =
2020-03-15 23:22:36 -04:00
UC . newButton ( LANG . ws _save , API . space . save ) ,
2020-03-09 11:02:09 -04:00
] , [
2020-03-15 23:22:36 -04:00
UC . newButton ( LANG . ws _cler , API . space . clear )
2020-03-09 11:02:09 -04:00
]
2020-04-16 23:59:13 -04:00
] , { modes : ALL , expert : true } ) ,
2020-03-09 11:02:09 -04:00
2020-03-16 12:11:30 -04:00
layout : UC . newGroup ( LANG . op _menu ) ,
2020-04-08 12:09:07 -04:00
expert : UC . newBoolean ( LANG . op _xprt _s , booleanSave , { title : LANG . op _xprt _l } ) ,
2020-03-29 20:23:48 -04:00
compact : UC . newBoolean ( LANG . op _comp _s , booleanSave , { title : LANG . op _comp _l } ) ,
2020-04-08 12:09:07 -04:00
dark : UC . newBoolean ( LANG . op _dark _s , booleanSave , { title : LANG . op _dark _l } ) ,
2020-03-16 12:11:30 -04:00
showOrigin : UC . newBoolean ( LANG . op _show _s , booleanSave , { title : LANG . op _show _l } ) ,
alignTop : UC . newBoolean ( LANG . op _alig _s , booleanSave , { title : LANG . op _alig _l , modes : CAM } ) ,
autoLayout : UC . newBoolean ( LANG . op _auto _s , booleanSave , { title : LANG . op _auto _l } ) ,
2020-04-08 12:09:07 -04:00
freeLayout : UC . newBoolean ( LANG . op _free _s , booleanSave , { title : LANG . op _free _l , modes : ALL , expert : true } ) ,
reverseZoom : UC . newBoolean ( LANG . op _invr _s , booleanSave , { title : LANG . op _invr _l , modes : ALL , expert : true } ) ,
2020-03-16 13:11:02 -04:00
units : UC . newSelect ( LANG . op _unit _s , { title : LANG . op _unit _l , modes : CAM } , "units" ) ,
2020-03-16 12:11:30 -04:00
// allow modules to insert new items at the bottom of the left menu
appendLeft : UC . checkpoint ( ) ,
layers : UC . setGroup ( $ ( "layers" ) ) ,
layerOutline : UC . newBoolean ( LANG . la _olin , onLayerToggle , { modes : LOCAL ? ALL : FDM _LASER } ) ,
2020-04-17 19:03:05 -04:00
layerTrace : UC . newBoolean ( LANG . la _trce , onLayerToggle , { modes : FDM _LASER } ) ,
2020-03-16 12:11:30 -04:00
layerFacing : UC . newBoolean ( LANG . la _face , onLayerToggle , { modes : CAM } ) ,
layerRough : UC . newBoolean ( LANG . la _ruff , onLayerToggle , { modes : CAM } ) ,
layerFinish : UC . newBoolean ( LANG . la _fini , onLayerToggle , { modes : CAM } ) ,
layerFinishX : UC . newBoolean ( LANG . la _finx , onLayerToggle , { modes : CAM } ) ,
layerFinishY : UC . newBoolean ( LANG . la _finy , onLayerToggle , { modes : CAM } ) ,
2020-04-13 19:28:17 -04:00
layerDelta : UC . newBoolean ( LANG . la _dlta , onLayerToggle , { modes : FDM _SLA } ) ,
layerSolid : UC . newBoolean ( LANG . la _slds , onLayerToggle , { modes : FDM _SLA } ) ,
2020-03-16 12:11:30 -04:00
layerFill : UC . newBoolean ( LANG . la _fill , onLayerToggle , { modes : FDM } ) ,
layerSparse : UC . newBoolean ( LANG . la _sprs , onLayerToggle , { modes : FDM } ) ,
2020-04-23 22:44:22 -04:00
layerSupport : UC . newBoolean ( LANG . la _sprt , onLayerToggle , { modes : FDM _SLA } ) ,
2020-03-16 12:11:30 -04:00
layerPrint : UC . newBoolean ( LANG . la _prnt , onLayerToggle ) ,
2020-04-17 19:03:05 -04:00
layerMoves : UC . newBoolean ( LANG . la _move , onLayerToggle , { modes : GCODE } ) ,
2020-03-16 12:11:30 -04:00
2020-03-29 13:15:40 -04:00
settingsGroup : UC . newGroup ( LANG . se _menu , control , { region : "right" } ) ,
2020-03-09 11:02:09 -04:00
settingsTable : UC . newTableRow ( [
[
UI . settingsLoad =
2020-03-16 12:11:30 -04:00
UC . newButton ( LANG . se _load , settingsLoad ) ,
2020-03-09 11:02:09 -04:00
UI . settingsSave =
2020-03-16 12:11:30 -04:00
UC . newButton ( LANG . se _save , settingsSave )
2020-03-09 11:02:09 -04:00
]
] ) ,
2020-03-16 13:11:02 -04:00
process : UC . newGroup ( LANG . sl _menu , control , { modes : FDM _LASER } ) ,
sliceHeight : UC . newInput ( LANG . sl _lahi _s , { title : LANG . sl _lahi _l , convert : UC . toFloat , modes : FDM } ) ,
sliceShells : UC . newInput ( LANG . sl _shel _s , { title : LANG . sl _shel _l , convert : UC . toInt , modes : FDM } ) ,
sliceTopLayers : UC . newInput ( LANG . sl _ltop _s , { title : LANG . sl _ltop _l , convert : UC . toInt , modes : FDM } ) ,
sliceSolidLayers : UC . newInput ( LANG . sl _lsld _s , { title : LANG . sl _lsld _l , convert : UC . toInt , modes : FDM } ) ,
sliceBottomLayers : UC . newInput ( LANG . sl _lbot _s , { title : LANG . sl _lbot _l , convert : UC . toInt , modes : FDM } ) ,
process : UC . newGroup ( LANG . fi _menu , control , { modes : FDM } ) ,
sliceFillType : UC . newSelect ( LANG . fi _type , { modes : FDM } , "infill" ) ,
sliceFillSparse : UC . newInput ( LANG . fi _pcnt _s , { title : LANG . fi _pcnt _l , convert : UC . toFloat , bound : UC . bound ( 0.0 , 1.0 ) , modes : FDM } ) ,
sliceFillAngle : UC . newInput ( LANG . fi _angl _s , { title : LANG . fi _angl _l , convert : UC . toFloat , modes : FDM , expert : true } ) ,
sliceFillOverlap : UC . newInput ( LANG . fi _over _s , { title : LANG . fi _over _l , convert : UC . toFloat , bound : UC . bound ( 0.0 , 2.0 ) , modes : FDM , expert : true } ) ,
firstLayer : UC . newGroup ( LANG . fl _menu , null , { modes : FDM } ) ,
firstSliceHeight : UC . newInput ( LANG . fl _lahi _s , { title : LANG . fl _lahi _l , convert : UC . toFloat , modes : FDM } ) ,
firstLayerRate : UC . newInput ( LANG . fl _rate _s , { title : LANG . fl _rate _l , convert : UC . toFloat , modes : FDM } ) ,
firstLayerFillRate : UC . newInput ( LANG . fl _frat _s , { title : LANG . fl _frat _l , convert : UC . toFloat , modes : FDM } ) ,
2020-03-16 16:58:38 -04:00
firstLayerPrintMult : UC . newInput ( LANG . fl _mult _s , { title : LANG . fl _mult _l , convert : UC . toFloat , modes : FDM , expert : true } ) ,
2020-03-16 13:11:02 -04:00
outputBrimCount : UC . newInput ( LANG . fl _skrt _s , { title : LANG . fl _skrt _l , convert : UC . toInt , modes : FDM } ) ,
outputBrimOffset : UC . newInput ( LANG . fl _skro _s , { title : LANG . fl _skro _l , convert : UC . toFloat , modes : FDM } ) ,
2020-03-16 16:58:38 -04:00
firstLayerNozzleTemp : UC . newInput ( LANG . fl _nozl _s , { title : LANG . fl _nozl _l , convert : UC . toInt , modes : FDM , expert : true } ) ,
firstLayerBedTemp : UC . newInput ( LANG . fl _bedd _s , { title : LANG . fl _bedd _l , convert : UC . toInt , modes : FDM , expert : true } ) ,
2020-03-16 13:11:02 -04:00
support : UC . newGroup ( LANG . sp _menu , null , { modes : FDM } ) ,
2020-03-16 16:58:38 -04:00
sliceSupportDensity : UC . newInput ( LANG . sp _dens _s , { title : LANG . sp _dens _l , convert : UC . toFloat , bound : UC . bound ( 0.05 , 1.0 ) , modes : FDM } ) ,
sliceSupportSize : UC . newInput ( LANG . sp _size _s , { title : LANG . sp _size _l , bound : UC . bound ( 1.0 , 200.0 ) , convert : UC . toFloat , modes : FDM } ) ,
sliceSupportOffset : UC . newInput ( LANG . sp _offs _s , { title : LANG . sp _offs _l , bound : UC . bound ( 0.0 , 200.0 ) , convert : UC . toFloat , modes : FDM } ) ,
sliceSupportGap : UC . newInput ( LANG . sp _gaps _s , { title : LANG . sp _gaps _l , bound : UC . bound ( 0 , 5 ) , convert : UC . toInt , modes : FDM , expert : true } ) ,
sliceSupportSpan : UC . newInput ( LANG . sp _span _s , { title : LANG . sp _span _l , bound : UC . bound ( 0.0 , 200.0 ) , convert : UC . toFloat , modes : FDM } ) ,
sliceSupportArea : UC . newInput ( LANG . sp _area _s , { title : LANG . sp _area _l , bound : UC . bound ( 0.1 , 200.0 ) , convert : UC . toFloat , modes : FDM } ) ,
sliceSupportExtra : UC . newInput ( LANG . sp _xpnd _s , { title : LANG . sp _xpnd _l , bound : UC . bound ( 0.0 , 200.0 ) , convert : UC . toFloat , modes : FDM , expert : true } ) ,
2020-04-10 15:19:47 -04:00
sliceSupportNozzle : UC . newSelect ( LANG . sp _nozl _s , { title : LANG . sp _nozl _l , modes : FDM , expert : true } , "extruders" ) ,
2020-03-16 16:58:38 -04:00
sliceSupportEnable : UC . newBoolean ( LANG . enable , onBooleanClick , { modes : FDM } ) ,
laserOffset : UC . newInput ( LANG . ls _offs _s , { title : LANG . ls _offs _l , convert : UC . toFloat , modes : LASER } ) ,
laserSliceHeight : UC . newInput ( LANG . ls _lahi _s , { title : LANG . ls _lahi _l , convert : UC . toFloat , modes : LASER } ) ,
laserSliceSingle : UC . newBoolean ( LANG . ls _sngl _s , onBooleanClick , { title : LANG . ls _sngl _l , modes : LASER } ) ,
camCommon : UC . newGroup ( LANG . cc _menu , null , { modes : CAM } ) ,
camFastFeed : UC . newInput ( LANG . cc _rapd _s , { title : LANG . cc _rapd _l , convert : UC . toInt , modes : CAM } ) ,
roughing : UC . newGroup ( LANG . cr _menu , null , { modes : CAM } ) ,
roughingTool : UC . newSelect ( LANG . cc _tool , { modes : CAM } ) ,
roughingSpindle : UC . newInput ( LANG . cc _spnd _s , { title : LANG . cc _spnd _l , convert : UC . toInt , modes : CAM } ) ,
roughingOver : UC . newInput ( LANG . cc _sovr _s , { title : LANG . cc _sovr _l , convert : UC . toFloat , bound : UC . bound ( 0.1 , 1.0 ) , modes : CAM } ) ,
roughingDown : UC . newInput ( LANG . cc _sdwn _s , { title : LANG . cc _sdwn _l , convert : UC . toFloat , modes : CAM } ) ,
roughingSpeed : UC . newInput ( LANG . cc _feed _s , { title : LANG . cc _feed _l , convert : UC . toInt , modes : CAM } ) ,
roughingPlunge : UC . newInput ( LANG . cc _plng _s , { title : LANG . cc _plng _l , convert : UC . toInt , modes : CAM } ) ,
roughingStock : UC . newInput ( LANG . cr _lsto _s , { title : LANG . cr _lsto _l , convert : UC . toFloat , modes : CAM } ) ,
camPocketOnlyRough : UC . newBoolean ( LANG . cc _pock _s , onBooleanClick , { title : LANG . cc _pock _l , modes : CAM } ) ,
camEaseDown : UC . newBoolean ( LANG . cr _ease _s , onBooleanClick , { title : LANG . cr _ease _l , modes : CAM } ) ,
roughingOn : UC . newBoolean ( LANG . enable , onBooleanClick , { modes : CAM } ) ,
finishing : UC . newGroup ( LANG . cf _menu , null , { modes : CAM } ) ,
finishingTool : UC . newSelect ( LANG . cc _tool , { modes : CAM } ) ,
finishingSpindle : UC . newInput ( LANG . cc _spnd _s , { title : LANG . cc _spnd _l , convert : UC . toInt , modes : CAM } ) ,
finishingOver : UC . newInput ( LANG . cc _sovr _s , { title : LANG . cc _sovr _l , convert : UC . toFloat , bound : UC . bound ( 0.05 , 1.0 ) , modes : CAM } ) ,
finishingDown : UC . newInput ( LANG . cc _sdwn _s , { title : LANG . cc _sdwn _l , convert : UC . toFloat , modes : CAM } ) ,
finishingAngle : UC . newInput ( LANG . cf _angl _s , { title : LANG . cf _angl _l , convert : UC . toFloat , bound : UC . bound ( 45 , 90 ) , modes : CAM } ) ,
finishingSpeed : UC . newInput ( LANG . cc _feed _s , { title : LANG . cc _feed _l , convert : UC . toInt , modes : CAM } ) ,
finishingPlunge : UC . newInput ( LANG . cc _plng _s , { title : LANG . cc _plng _l , convert : UC . toInt , modes : CAM } ) ,
camPocketOnlyFinish : UC . newBoolean ( LANG . cc _pock _s , onBooleanClick , { title : LANG . cc _pock _l , modes : CAM } ) ,
finishingOn : UC . newBoolean ( LANG . cf _watr _s , onBooleanClick , { title : LANG . cf _watr _l , modes : CAM } ) ,
finishingXOn : UC . newBoolean ( LANG . cf _linx _s , onBooleanClick , { title : LANG . cf _linx _l , modes : CAM } ) ,
finishingYOn : UC . newBoolean ( LANG . cf _liny _s , onBooleanClick , { title : LANG . cf _liny _l , modes : CAM } ) ,
finishCurvesOnly : UC . newBoolean ( LANG . cf _curv _s , onBooleanClick , { title : LANG . cf _curv _l , modes : CAM } ) ,
drilling : UC . newGroup ( LANG . cd _menu , null , { modes : CAM } ) ,
drillTool : UC . newSelect ( LANG . cc _tool , { modes : CAM } ) ,
drillSpindle : UC . newInput ( LANG . cc _spnd _s , { title : LANG . cc _spnd _l , convert : UC . toInt , modes : CAM } ) ,
drillDown : UC . newInput ( LANG . cd _plpr _s , { title : LANG . cd _plpr _l , convert : UC . toFloat , modes : CAM } ) ,
drillDownSpeed : UC . newInput ( LANG . cc _plng _s , { title : LANG . cc _plng _l , convert : UC . toFloat , modes : CAM } ) ,
drillDwell : UC . newInput ( LANG . cd _dwll _s , { title : LANG . cd _dwll _l , convert : UC . toFloat , modes : CAM } ) ,
drillLift : UC . newInput ( LANG . cd _lift _s , { title : LANG . cd _lift _l , convert : UC . toFloat , modes : CAM } ) ,
drillingOn : UC . newBoolean ( LANG . enable , onBooleanClick , { modes : CAM } ) ,
camTabs : UC . newGroup ( LANG . ct _menu , null , { modes : CAM } ) ,
camTabsAngle : UC . newInput ( LANG . ct _angl _s , { title : LANG . ct _angl _l , convert : UC . toInt , bound : UC . bound ( 0 , 360 ) , modes : CAM } ) ,
camTabsCount : UC . newInput ( LANG . ct _numb _s , { title : LANG . ct _numb _l , convert : UC . toInt , bound : UC . bound ( 1 , 20 ) , modes : CAM } ) ,
camTabsWidth : UC . newInput ( LANG . ct _wdth _s , { title : LANG . ct _wdth _l , convert : UC . toFloat , bound : UC . bound ( 0.1 , 100 ) , modes : CAM } ) ,
camTabsHeight : UC . newInput ( LANG . ct _hght _s , { title : LANG . ct _hght _l , convert : UC . toFloat , bound : UC . bound ( 0.1 , 100 ) , modes : CAM } ) ,
camTabsOn : UC . newBoolean ( LANG . enable , onBooleanClick , { title : LANG . ct _nabl _l , modes : CAM } ) ,
output : UC . newGroup ( LANG . fr _menu , null , { modes : FDM } ) ,
outputRaftSpacing : UC . newInput ( LANG . fr _spac _s , { title : LANG . fr _spac _l , convert : UC . toFloat , bound : UC . bound ( 0.0 , 3.0 ) , modes : FDM } ) ,
outputRaft : UC . newBoolean ( LANG . enable , onBooleanClick , { title : LANG . fr _nabl _l , modes : FDM } ) ,
2020-04-13 19:28:17 -04:00
output : UC . newGroup ( LANG . ou _menu , null , { modes : GCODE } ) ,
2020-03-16 16:58:38 -04:00
outputTileSpacing : UC . newInput ( LANG . ou _spac _c , { title : LANG . ou _spac _l , convert : UC . toInt , modes : LASER } ) ,
outputTileScaling : UC . newInput ( LANG . ou _scal _s , { title : LANG . ou _scal _l , convert : UC . toInt , bound : UC . bound ( 0.1 , 100 ) , modes : LASER } ) ,
outputLaserPower : UC . newInput ( LANG . ou _powr _s , { title : LANG . ou _powr _l , convert : UC . toInt , bound : UC . bound ( 1 , 100 ) , modes : LASER } ) ,
outputLaserSpeed : UC . newInput ( LANG . ou _sped _s , { title : LANG . ou _sped _l , convert : UC . toInt , modes : LASER } ) ,
outputLaserMerged : UC . newBoolean ( LANG . ou _mrgd _s , onBooleanClick , { title : LANG . ou _mrgd _l , modes : LASER } ) ,
outputLaserGroup : UC . newBoolean ( LANG . ou _grpd _s , onBooleanClick , { title : LANG . ou _grpd _l , modes : LASER } ) ,
outputTemp : UC . newInput ( LANG . ou _nozl _s , { title : LANG . ou _nozl _l , convert : UC . toInt , modes : FDM } ) ,
outputBedTemp : UC . newInput ( LANG . ou _bedd _s , { title : LANG . ou _bedd _l , convert : UC . toInt , modes : FDM } ) ,
outputFeedrate : UC . newInput ( LANG . ou _feed _s , { title : LANG . ou _feed _l , convert : UC . toInt , modes : FDM } ) ,
outputFinishrate : UC . newInput ( LANG . ou _fini _s , { title : LANG . ou _fini _l , convert : UC . toInt , modes : FDM } ) ,
outputSeekrate : UC . newInput ( LANG . ou _move _s , { title : LANG . ou _move _l , convert : UC . toInt , modes : FDM } ) ,
outputShellMult : UC . newInput ( LANG . ou _shml _s , { title : LANG . ou _exml _l , convert : UC . toFloat , bound : UC . bound ( 0.0 , 2.0 ) , modes : FDM } ) ,
outputFillMult : UC . newInput ( LANG . ou _flml _s , { title : LANG . ou _exml _l , convert : UC . toFloat , bound : UC . bound ( 0.0 , 2.0 ) , modes : FDM } ) ,
outputSparseMult : UC . newInput ( LANG . ou _spml _s , { title : LANG . ou _exml _l , convert : UC . toFloat , bound : UC . bound ( 0.0 , 2.0 ) , modes : FDM } ) ,
outputFanLayer : UC . newInput ( LANG . ou _fanl _s , { title : LANG . ou _fanl _l , convert : UC . toInt , bound : UC . bound ( 0 , 100 ) , modes : FDM , expert : true } ) ,
camTolerance : UC . newInput ( LANG . ou _toll _s , { title : LANG . ou _toll _l , convert : UC . toFloat , bound : UC . bound ( 0.001 , 1.0 ) , modes : CAM } ) ,
camZTopOffset : UC . newInput ( LANG . ou _ztof _s , { title : LANG . ou _ztof _l , convert : UC . toFloat , modes : CAM } ) ,
camZBottom : UC . newInput ( LANG . ou _zbot _s , { title : LANG . ou _zbot _l , convert : UC . toFloat , modes : CAM } ) ,
camZClearance : UC . newInput ( LANG . ou _zclr _s , { title : LANG . ou _zclr _l , convert : UC . toFloat , bound : UC . bound ( 0.01 , 100 ) , modes : CAM } ) ,
outputClockwise : UC . newBoolean ( LANG . ou _conv _s , onBooleanClick , { title : LANG . ou _conv _l , modes : CAM } ) ,
camDepthFirst : UC . newBoolean ( LANG . ou _depf _s , onBooleanClick , { title : LANG . ou _depf _l , modes : CAM } ) ,
camStock : UC . newGroup ( LANG . cs _menu , null , { modes : CAM } ) ,
camStockX : UC . newInput ( LANG . cs _wdth _s , { title : LANG . cs _wdth _l , convert : UC . toFloat , bound : UC . bound ( 0 , 9999 ) , modes : CAM } ) ,
camStockY : UC . newInput ( LANG . cs _dpth _s , { title : LANG . cs _dpth _l , convert : UC . toFloat , bound : UC . bound ( 0 , 9999 ) , modes : CAM } ) ,
camStockZ : UC . newInput ( LANG . cs _hght _s , { title : LANG . cs _hght _l , convert : UC . toFloat , bound : UC . bound ( 0 , 9999 ) , modes : CAM } ) ,
camStockOffset : UC . newBoolean ( LANG . cs _offs _s , onBooleanClick , { title : LANG . cs _offs _l , modes : CAM } ) ,
outputOriginBounds : UC . newBoolean ( LANG . or _bnds _s , onBooleanClick , { title : LANG . or _bnds _l , modes : LASER } ) ,
outputOriginCenter : UC . newBoolean ( LANG . or _cntr _s , onBooleanClick , { title : LANG . or _cntr _l , modes : CAM _LASER } ) ,
camOriginTop : UC . newBoolean ( LANG . or _topp _s , onBooleanClick , { title : LANG . or _topp _l , modes : CAM } ) ,
advanced : UC . newGroup ( LANG . ad _menu , null , { modes : FDM , expert : true } ) ,
outputRetractDist : UC . newInput ( LANG . ad _rdst _s , { title : LANG . ad _rdst _l , convert : UC . toFloat , modes : FDM , expert : true } ) ,
outputRetractSpeed : UC . newInput ( LANG . ad _rrat _s , { title : LANG . ad _rrat _l , convert : UC . toInt , modes : FDM , expert : true } ) ,
outputRetractDwell : UC . newInput ( LANG . ad _rdwl _s , { title : LANG . ad _rdwl _l , convert : UC . toInt , modes : FDM , expert : true } ) ,
outputCoastDist : UC . newInput ( LANG . ad _scst _s , { title : LANG . ad _scst _l , bound : UC . bound ( 0.0 , 10 ) , convert : UC . toFloat , modes : FDM , expert : true } ) ,
// outputWipeDistance: UC.newInput("wipe", {title:"non-printing move at\close of polygon\nin millimeters", bound:UC.bound(0.0,10), convert:UC.toFloat, modes:FDM, expert:true}),
sliceSolidMinArea : UC . newInput ( LANG . ad _msol _s , { title : LANG . ad _msol _l , convert : UC . toFloat , modes : FDM , expert : true } ) ,
sliceMinHeight : UC . newInput ( LANG . ad _minl _s , { title : LANG . ad _minl _l , bound : UC . bound ( 0 , 3.0 ) , convert : UC . toFloat , modes : FDM , expert : true } ) ,
outputMinSpeed : UC . newInput ( LANG . ad _mins _s , { title : LANG . ad _mins _l , bound : UC . bound ( 5 , 200 ) , convert : UC . toFloat , modes : FDM , expert : true } ) ,
outputShortPoly : UC . newInput ( LANG . ad _spol _s , { title : LANG . ad _spol _l , bound : UC . bound ( 0 , 200 ) , convert : UC . toFloat , modes : FDM , expert : true } ) ,
zHopDistance : UC . newInput ( LANG . ad _zhop _s , { title : LANG . ad _zhop _l , bound : UC . bound ( 0 , 3.0 ) , convert : UC . toFloat , modes : FDM , expert : true } ) ,
antiBacklash : UC . newInput ( LANG . ad _abkl _s , { title : LANG . ad _abkl _l , bound : UC . bound ( 0 , 3 ) , convert : UC . toInt , modes : FDM , expert : true } ) ,
// detectThinWalls: UC.newBoolean("thin wall fill", onBooleanClick, {title: "detect and fill thin openings\nbetween shells walls", modes:FDM, expert:true})
2020-04-20 08:57:48 -04:00
gcodePauseLayers : UC . newInput ( LANG . ag _paws _s , { title : LANG . ag _paws _l , modes : FDM , expert : true , comma : true } ) ,
2020-04-13 19:28:17 -04:00
outputLayerRetract : UC . newBoolean ( LANG . ad _lret _s , onBooleanClick , { title : LANG . ad _lret _l , modes : FDM , expert : true } ) ,
// SLA
2020-04-15 11:52:44 -04:00
slaProc : UC . newGroup ( 'slice' , null , { modes : SLA , group : "sla-slice" } ) ,
2020-04-14 15:57:34 -04:00
slaSlice : UC . newInput ( 'layer height' , { title : 'slice height' , convert : UC . toFloat , modes : SLA } ) ,
2020-04-15 15:20:02 -04:00
slaShell : UC . newInput ( 'hollow shell' , { title : 'shell thickness in mm\nuse multiple of layer height\nuse 0 for solid' , convert : UC . toFloat , modes : SLA } ) ,
2020-04-14 15:57:34 -04:00
slaOpenTop : UC . newBoolean ( 'open top' , onBooleanClick , { title : 'solid layers' , modes : SLA } ) ,
slaOpenBase : UC . newBoolean ( 'open base' , onBooleanClick , { title : 'bottom layers' , modes : SLA } ) ,
2020-04-16 12:01:47 -04:00
// SLA
slaOutput : UC . newGroup ( 'layers' , null , { modes : SLA , group : "sla-layers" } ) ,
slaLayerOn : UC . newInput ( 'light on time' , { title : 'layer light on\ntime in seconds' , convert : UC . toFloat , modes : SLA } ) ,
slaLayerOff : UC . newInput ( 'light off time' , { title : 'layer light off\ntime in seconds' , convert : UC . toFloat , modes : SLA } ) ,
slaPeelDist : UC . newInput ( 'peel distance' , { title : 'peel distance\nin millimeters' , convert : UC . toFloat , modes : SLA } ) ,
slaPeelLiftRate : UC . newInput ( 'peel lift rate' , { title : 'peel lift speed\nin mm/sec' , convert : UC . toFloat , modes : SLA } ) ,
slaPeelDropRate : UC . newInput ( 'peel drop rate' , { title : 'peel drop speed\nin mm/sec' , convert : UC . toFloat , modes : SLA } ) ,
slaOutput : UC . newGroup ( 'base layers' , null , { modes : SLA , group : "sla-base" } ) ,
slaBaseLayers : UC . newInput ( 'layer count' , { title : 'number of\nbase layers' , convert : UC . toInt , modes : SLA } ) ,
slaBaseOn : UC . newInput ( 'light on time' , { title : 'base layer light on\ntime in seconds' , convert : UC . toFloat , modes : SLA } ) ,
slaBaseOff : UC . newInput ( 'light off time' , { title : 'base layer light on\ntime in seconds' , convert : UC . toFloat , modes : SLA } ) ,
slaBasePeelDist : UC . newInput ( 'peel distance' , { title : 'peel distance\nin millimeters' , convert : UC . toFloat , modes : SLA } ) ,
slaBasePeelLiftRate : UC . newInput ( 'peel lift rate' , { title : 'peel lift speed\nin mm/sec' , convert : UC . toFloat , modes : SLA } ) ,
2020-04-16 18:27:28 -04:00
2020-04-19 21:32:06 -04:00
slaFill : UC . newGroup ( 'infill' , null , { modes : SLA , group : "sla-infill" } ) ,
2020-04-17 14:20:49 -04:00
slaFillDensity : UC . newInput ( 'density' , { title : 'percent infill\n0.0-1.0' , convert : UC . toFloat , bound : UC . bound ( 0 , 1 ) , modes : SLA } ) ,
2020-04-17 19:03:05 -04:00
slaFillLine : UC . newInput ( 'line width' , { title : 'hatch line width\nin millimeters' , convert : UC . toFloat , bound : UC . bound ( 0 , 5 ) , modes : SLA } ) ,
2020-04-18 22:12:50 -04:00
2020-04-23 18:01:12 -04:00
slaSupport : LOCAL ? UC . newGroup ( 'support' , null , { modes : SLA , group : "sla-support" } ) : null ,
slaSupportLayers : LOCAL ? UC . newInput ( 'layers' , { title : 'base support layers\n0-10' , convert : UC . toInt , bound : UC . bound ( 0 , 10 ) , modes : SLA } ) : null ,
2020-04-24 10:43:03 -04:00
slaSupportDensity : LOCAL ? UC . newInput ( 'density' , { title : 'used to compute the\nnumber of support pillars\n0.0-1.0 (0 = disable)' , convert : UC . toFloat , bound : UC . bound ( 0 , 1 ) , modes : SLA } ) : null ,
2020-04-23 18:01:12 -04:00
2020-04-18 22:12:50 -04:00
slaOutput : UC . newGroup ( 'output' , null , { modes : SLA , group : "sla-first" } ) ,
slaFirstOffset : UC . newInput ( 'z offset' , { title : 'z layer offset\nalmost always 0.0\n0.0-1.0 in millimeters' , convert : UC . toFloat , bound : UC . bound ( 0 , 1 ) , modes : SLA , expert : true } ) ,
slaAntiAlias : UC . newSelect ( 'anti alias' , { title : 'enable anti-aliasing\nproduces larger files' , modes : SLA } , "antialias" ) ,
2020-03-09 11:02:09 -04:00
} ) ;
2020-03-20 20:56:24 -04:00
if ( ! lang _set ) {
// for english only, add underlined labels for hotkeys
UI . setupDevices . innerHTML = "D<u>e</u>vices" ;
UI . setupTools . innerHTML = "T<u>o</u>ols" ;
UI . modeArrange . innerHTML = "<u>A</u>rrange" ;
UI . modeSlice . innerHTML = "<u>S</u>lice" ;
UI . modePreview . innerHTML = "<u>P</u>review" ;
UI . modeExport . innerHTML = "E<u>x</u>port" ;
}
2020-04-02 17:06:38 -04:00
// populate language drop-down
let lp = $ ( 'langpop' ) ;
let elp = DOC . createElement ( "div" ) ;
let dlp = DOC . createElement ( "div" ) ;
elp . appendChild ( DOC . createTextNode ( 'english' ) ) ;
dlp . appendChild ( DOC . createTextNode ( 'danish' ) ) ;
lp . appendChild ( elp ) ;
lp . appendChild ( dlp ) ;
elp . onclick = function ( ) {
SDB . setItem ( 'kiri-lang' , 'en-us' ) ;
LOC . reload ( ) ;
} ;
dlp . onclick = function ( ) {
SDB . setItem ( 'kiri-lang' , 'da-dk' ) ;
LOC . reload ( ) ;
} ;
2020-03-09 11:02:09 -04:00
SPACE . addEventHandlers ( self , [
'keyup' , keyUpHandler ,
'keydown' , keyDownHandler ,
'keypress' , keyHandler ,
'dragover' , dragOverHandler ,
'dragleave' , dragLeave ,
'drop' , dropHandler
] ) ;
2020-04-11 09:22:37 -04:00
function selectionSize ( e ) {
let dv = parseFloat ( e . target . value || 1 ) ,
pv = parseFloat ( e . target . was || 1 ) ,
ra = dv / pv ,
xv = parseFloat ( UI . sizeX . was ) ,
yv = parseFloat ( UI . sizeY . was ) ,
zv = parseFloat ( UI . sizeZ . was ) ,
xr = ( UI . lockX . checked ? ra : 1 ) ,
yr = ( UI . lockY . checked ? ra : 1 ) ,
zr = ( UI . lockZ . checked ? ra : 1 ) ;
API . selection . scale ( xr , yr , zr ) ;
UI . sizeX . was = UI . sizeX . value = xv * xr ;
UI . sizeY . was = UI . sizeY . value = yv * yr ;
UI . sizeZ . was = UI . sizeZ . value = zv * zr ;
}
function selectionScale ( e ) {
let dv = parseFloat ( e . target . value || 1 ) ,
pv = parseFloat ( e . target . was || 1 ) ,
ra = dv / pv ,
xv = parseFloat ( UI . scaleX . was ) ,
yv = parseFloat ( UI . scaleY . was ) ,
zv = parseFloat ( UI . scaleZ . was ) ,
xr = ( UI . lockX . checked ? ra : 1 ) ,
yr = ( UI . lockY . checked ? ra : 1 ) ,
zr = ( UI . lockZ . checked ? ra : 1 ) ;
API . selection . scale ( xr , yr , zr ) ;
UI . scaleX . was = UI . scaleX . value = xv * xr ;
UI . scaleY . was = UI . scaleY . value = yv * yr ;
UI . scaleZ . was = UI . scaleZ . value = zv * zr ;
}
function selectionRotate ( e ) {
let deg = parseFloat ( e . target . value ) * DEG ;
e . target . value = 0 ;
switch ( e . target . id . split ( '' ) . pop ( ) ) {
case 'x' : return API . selection . rotate ( deg , 0 , 0 ) ;
case 'y' : return API . selection . rotate ( 0 , deg , 0 ) ;
case 'z' : return API . selection . rotate ( 0 , 0 , deg ) ;
}
}
2020-03-09 11:02:09 -04:00
SPACE . onEnterKey ( [
2020-04-11 09:22:37 -04:00
UI . layerSpan , function ( ) { API . show . slices ( ) } ,
UI . layerID , function ( ) { API . show . layer ( UI . layerID . value ) } ,
UI . scaleX , selectionScale ,
UI . scaleY , selectionScale ,
UI . scaleZ , selectionScale ,
UI . sizeX , selectionSize ,
UI . sizeY , selectionSize ,
UI . sizeZ , selectionSize ,
UI . toolName , updateTool ,
UI . toolNum , updateTool ,
UI . toolFluteDiam , updateTool ,
UI . toolFluteLen , updateTool ,
UI . toolShaftDiam , updateTool ,
UI . toolShaftLen , updateTool ,
UI . toolTaperTip , updateTool ,
$ ( 'rot_x' ) , selectionRotate ,
$ ( 'rot_y' ) , selectionRotate ,
$ ( 'rot_z' ) , selectionRotate
2020-03-09 11:02:09 -04:00
] ) ;
UI . layerID . convert = UC . toFloat . bind ( UI . layerID ) ;
UI . layerSpan . convert = UC . toFloat . bind ( UI . layerSpan ) ;
UI . layerRange . onclick = function ( ) {
UI . layerRange . checked = ! ( UI . layerRange . checked || false ) ;
API . show . slices ( ) ;
} ;
$ ( 'layer-toggle' ) . onclick = function ( ev ) {
let ls = UI . layers . style ;
ls . display = ls . display !== 'block' ? 'block' : 'none' ;
UI . layers . style . left = ev . target . getBoundingClientRect ( ) . left + 'px' ;
} ;
UI . modelOpacity . onchange = UI . modelOpacity . onclick = function ( ev ) {
2020-03-09 18:08:08 -04:00
API . widgets . opacity ( parseInt ( UI . modelOpacity . value ) / 100 ) ;
2020-03-09 11:02:09 -04:00
} ;
UI . layerSlider . ondblclick = function ( ) {
UI . layerRange . checked = ! UI . layerRange . checked ;
API . show . slices ( ) ;
} ;
UI . layerSlider . onmousedown = function ( ev ) {
if ( ev . shiftKey ) UI . layerRange . checked = ! UI . layerRange . checked ;
} ;
UI . layerSlider . onclick = function ( ) {
2020-03-09 18:08:08 -04:00
API . show . layer ( UI . layerSlider . value ) ;
2020-03-09 11:02:09 -04:00
} ;
UI . layerSlider . onmousemove = UI . layerSlider . onchange = function ( ) {
2020-03-09 18:08:08 -04:00
API . show . layer ( UI . layerSlider . value ) ;
2020-03-09 11:02:09 -04:00
} ;
UI . layerSlider . onmouseup = function ( ) { API . focus ( ) } ;
UI . import . setAttribute ( "import" , "1" ) ;
UI . import . onclick = function ( ) {
2020-04-01 17:42:45 -04:00
UC . hidePoppers ( ) ;
2020-03-09 11:02:09 -04:00
API . dialog . show ( "catalog" ) ;
} ;
2020-04-16 23:59:13 -04:00
$ ( 'cache-close' ) . onclick = API . dialog . hide ;
2020-03-09 11:02:09 -04:00
UI . toolMetric . onclick = updateTool ;
UI . toolType . onchange = updateTool ;
2020-04-02 16:28:56 -04:00
$ ( 'apphelp' ) . onclick = API . help . show ;
2020-03-09 11:02:09 -04:00
SPACE . platform . setSize (
settings ( ) . device . bedWidth ,
settings ( ) . device . bedDepth ,
settings ( ) . device . bedHeight
) ;
2020-04-11 10:29:19 -04:00
if ( compact ) {
UI . selection . classList . add ( 'compact' ) ;
}
2020-04-08 09:38:32 -04:00
if ( dark ) {
SPACE . platform . setGrid ( 25 , 5 , 0x999999 , 0x333333 ) ;
SPACE . platform . opacity ( 0.8 ) ;
2020-04-08 14:31:32 -04:00
DOC . body . classList . add ( 'dark' ) ;
2020-04-08 09:38:32 -04:00
} else {
SPACE . platform . setGrid ( 25 , 5 , 0x999999 , 0xcccccc ) ;
SPACE . platform . opacity ( 0.3 ) ;
}
2020-03-09 11:02:09 -04:00
2020-03-30 14:10:36 -04:00
SPACE . mouse . downSelect ( function ( int , event ) {
// lay flat with meta or ctrl clicking a selected face
2020-04-12 14:46:14 -04:00
if ( int && ( event . ctrlKey || event . metaKey || API . feature . on _face _select ) ) {
2020-03-30 14:10:36 -04:00
let q = new THREE . Quaternion ( ) ;
q . setFromUnitVectors ( int . face . normal , new THREE . Vector3 ( 0 , 0 , - 1 ) ) ;
API . selection . rotate ( q ) ;
}
2020-03-09 11:02:09 -04:00
if ( API . view . get ( ) !== VIEWS . ARRANGE ) return null ;
return API . selection . meshes ( ) ;
} ) ;
SPACE . mouse . upSelect ( function ( selection , event ) {
if ( event && event . target . nodeName === "CANVAS" ) {
if ( selection ) {
platform . select ( selection . object . widget , event . shiftKey ) ;
} else {
platform . deselect ( ) ;
}
} else {
return API . widgets . meshes ( ) ;
}
} ) ;
2020-04-11 16:33:10 -04:00
// SPACE.mouse.onHover(function(d,me) {
// if (d) {
2020-04-12 21:28:49 -04:00
// // console.log(d,d.object.widget.id,d.face.materialIndex)
2020-04-11 16:33:10 -04:00
// // d.object.material.vertexColors = true;
// // d.object.material.needsUpdate = true;
// // d.face.vertexColors = [
// // new THREE.Color(0xffaa88),
// // new THREE.Color(0xffaa88),
// // new THREE.Color(0xffaa88)
// // ];
// // d.face.materialIndex = 1;
// } else {
// return API.widgets.meshes();
// }
// });
2020-03-09 11:02:09 -04:00
SPACE . mouse . onDrag ( function ( delta ) {
2020-03-16 17:26:12 -04:00
let dev = settings ( ) . device ;
let bmaxx = dev . bedWidth / 2 ;
let bminx = - bmaxx ;
let bmaxy = dev . bedDepth / 2 ;
let bminy = - bmaxy
2020-03-09 11:02:09 -04:00
if ( delta && UI . freeLayout . checked ) {
API . selection . for _widgets ( function ( widget ) {
2020-03-16 17:26:12 -04:00
let wbnd = widget . getBoundingBox ( ) ;
let wwid = wbnd . max . x - wbnd . min . x ;
2020-04-07 19:56:30 -04:00
let wminx = widget . track . pos . x + delta . x - wwid / 2 ;
2020-03-16 17:26:12 -04:00
let wmaxx = wminx + wwid + delta . x ;
if ( wminx < bminx || wmaxx > bmaxx ) return ;
let whei = wbnd . max . y - wbnd . min . y ;
2020-04-07 19:56:30 -04:00
let wminy = widget . track . pos . y + delta . y - whei / 2 ;
2020-03-16 17:26:12 -04:00
let wmaxy = wminy + whei + delta . y ;
if ( wminy < bminy || wmaxy > bmaxy ) return ;
2020-03-09 11:02:09 -04:00
widget . move ( delta . x , delta . y , 0 ) ;
2020-04-12 14:14:57 -04:00
API . event . emit ( 'widget.move' , { widget , delta } ) ;
2020-03-09 11:02:09 -04:00
} ) ;
platform . update _stock ( ) ;
} else {
return API . selection . meshes ( ) . length > 0 ;
}
} ) ;
2020-03-16 23:57:14 -04:00
API . space . restore ( init _two ) || checkSeed ( init _two ) || init _two ( ) ;
2020-03-09 11:02:09 -04:00
2020-03-16 23:57:14 -04:00
} ;
2020-03-09 11:02:09 -04:00
2020-03-16 23:57:14 -04:00
// SECOND STAGE INIT AFTER UI RESTORED
function init _two ( ) {
2020-04-20 17:50:23 -04:00
API . event . emit ( 'init.two' ) ;
2020-04-08 09:38:32 -04:00
let current = settings ( ) ,
control = current . controller ;
2020-03-16 23:57:14 -04:00
2020-04-15 15:20:02 -04:00
SPACE . scene . freeze ( true ) ;
2020-03-16 23:57:14 -04:00
platform . deselect ( ) ;
CATALOG . addFileListener ( updateCatalog ) ;
2020-04-08 09:38:32 -04:00
SPACE . view . setZoom ( control . reverseZoom , control . zoomSpeed ) ;
2020-03-16 23:57:14 -04:00
SPACE . platform . setZOff ( 0.2 ) ;
// restore UI state from settings
2020-04-08 09:38:32 -04:00
UI . showOrigin . checked = control . showOrigin ;
UI . freeLayout . checked = control . freeLayout ;
UI . autoLayout . checked = control . autoLayout ;
UI . alignTop . checked = control . alignTop ;
UI . reverseZoom . checked = control . reverseZoom ;
UI . compact . checked = control . compact ;
2020-03-16 23:57:14 -04:00
// load script extensions
if ( SETUP . s ) SETUP . s . forEach ( function ( lib ) {
let scr = DOC . createElement ( 'script' ) ;
2020-03-17 12:16:35 -04:00
scr . setAttribute ( 'defer' , true ) ;
2020-03-16 23:57:14 -04:00
scr . setAttribute ( 'src' , '/code/' + lib + '.js' ) ;
DOC . body . appendChild ( scr ) ;
STATS . add ( 'load_' + lib ) ;
2020-04-18 11:34:54 -04:00
API . event . emit ( 'load.lib' , lib ) ;
2020-03-16 23:57:14 -04:00
} ) ;
2020-03-09 11:02:09 -04:00
2020-03-16 23:57:14 -04:00
// load CSS extensions
if ( SETUP . ss ) SETUP . ss . forEach ( function ( style ) {
style = style . charAt ( 0 ) === '/' ? style : ` /kiri/style- ${ style } ` ;
let ss = DOC . createElement ( 'link' ) ;
ss . setAttribute ( "type" , "text/css" ) ;
ss . setAttribute ( "rel" , "stylesheet" ) ;
ss . setAttribute ( "href" , ` ${ style } .css ` ) ;
DOC . body . appendChild ( ss ) ;
} ) ;
2020-03-09 11:02:09 -04:00
2020-03-16 23:57:14 -04:00
// override stored settings
if ( SETUP . v ) SETUP . v . forEach ( function ( kv ) {
kv = kv . split ( '=' ) ;
SDB . setItem ( kv [ 0 ] , kv [ 1 ] ) ;
} ) ;
2020-03-09 11:02:09 -04:00
2020-03-16 23:57:14 -04:00
// import octoprint settings
if ( SETUP . ophost ) {
let ohost = API . const . OCTO = {
host : SETUP . ophost [ 0 ] ,
apik : SETUP . opkey ? SETUP . opkey [ 0 ] : ''
} ;
SDB [ 'octo-host' ] = ohost . host ;
SDB [ 'octo-apik' ] = ohost . apik ;
console . log ( { octoprint : ohost } ) ;
}
2020-03-09 11:02:09 -04:00
2020-03-16 23:57:14 -04:00
// optional set-and-lock mode (hides mode menu)
let SETMODE = SETUP . mode ? SETUP . mode [ 0 ] : null ;
2020-03-09 11:02:09 -04:00
2020-03-16 23:57:14 -04:00
// optional set-and-lock device (hides device menu)
let DEVNAME = SETUP . dev ? SETUP . dev [ 0 ] : null ;
2020-03-09 11:02:09 -04:00
2020-03-17 16:32:43 -04:00
// setup default mode and enable mode locking, if set
2020-03-16 23:57:14 -04:00
API . mode . set ( SETMODE || STARTMODE || current . mode , SETMODE ) ;
2020-03-09 11:02:09 -04:00
2020-03-17 16:32:43 -04:00
// update everything dependent on the platform size
platform . update _size ( ) ;
2020-03-09 11:02:09 -04:00
2020-03-17 16:32:43 -04:00
// ensure hot keys work even in iframes
API . focus ( ) ;
2020-03-09 11:02:09 -04:00
2020-03-16 23:57:14 -04:00
// place version number a couple of places to help users
UI . helpButton . title = ` ${ LANG . version } ` + KIRI . version ;
2020-03-09 11:02:09 -04:00
2020-03-16 23:57:14 -04:00
// restore expert setting preference
2020-04-08 12:09:07 -04:00
UC . setExpert ( control . expert ) ;
2020-03-09 11:02:09 -04:00
2020-03-16 23:57:14 -04:00
// setup tab visibility watcher
// DOC.addEventListener('visibilitychange', function() { document.title = document.hidden });
2020-03-09 11:02:09 -04:00
2020-03-16 23:57:14 -04:00
// ensure settings has gcode
selectDevice ( DEVNAME || API . device . get ( ) , DEVNAME ) ;
2020-03-09 11:02:09 -04:00
2020-03-16 23:57:14 -04:00
// ensure field data propagation
API . conf . update ( ) ;
2020-03-09 11:02:09 -04:00
2020-03-16 23:57:14 -04:00
// load settings provided in url hash
loadSettingsFromServer ( ) ;
2020-03-09 11:02:09 -04:00
2020-03-16 23:57:14 -04:00
// clear alerts as they build up
setInterval ( API . event . alerts , 1000 ) ;
2020-03-10 14:23:42 -04:00
2020-03-17 16:32:43 -04:00
// add hide-alerts-on-alert-click
2020-03-16 23:57:14 -04:00
UI . alert . dialog . onclick = function ( ) {
API . event . alerts ( true ) ;
} ;
2020-03-09 11:02:09 -04:00
2020-03-17 16:32:43 -04:00
// default to ARRANGE view mode
2020-03-16 23:57:14 -04:00
API . view . set ( VIEWS . ARRANGE ) ;
2020-03-17 10:44:42 -04:00
2020-03-17 16:32:43 -04:00
// add ability to override
2020-03-28 16:06:22 -04:00
API . show . controls ( API . feature . controls ) ;
2020-03-17 16:32:43 -04:00
2020-03-18 19:17:20 -04:00
// set initial layer slider size
API . dialog . update ( ) ;
2020-03-17 10:44:42 -04:00
// show version on startup
API . show . alert ( ` ${ LANG . version } ${ KIRI . version } ` ) ;
2020-03-17 16:32:43 -04:00
if ( ! SETUP . s ) console . log ( ` kiri | init main | ${ KIRI . version } ` ) ;
2020-03-17 18:32:16 -04:00
// send init-done event
API . event . emit ( 'init-done' , STATS ) ;
2020-04-15 15:20:02 -04:00
SPACE . scene . freeze ( false ) ;
2020-03-17 18:32:16 -04:00
}
// if a language needs to load, the script is injected and loaded
// first. once this loads, or doesn't, the initialization begins
let lang _set = undefined ;
2020-03-20 16:06:33 -04:00
let lang = SETUP . ln ? SETUP . ln [ 0 ] : SDB . getItem ( 'kiri-lang' ) || KIRI . lang . get ( ) ;
2020-03-18 18:22:57 -04:00
// inject language script if not english
if ( lang && lang !== 'en' && lang !== 'en-us' ) {
lang _set = lang ;
let scr = DOC . createElement ( 'script' ) ;
// scr.setAttribute('defer',true);
scr . setAttribute ( 'src' , ` /kiri/lang/ ${ lang } .js ` ) ;
( DOC . body || DOC . head ) . appendChild ( scr ) ;
STATS . set ( 'll' , lang ) ;
scr . onload = function ( ) {
KIRI . lang . set ( lang ) ;
init _one ( ) ;
} ;
scr . onerror = function ( err ) {
console . log ( { language _load _error : err , lang } )
init _one ( ) ;
2020-03-17 18:32:16 -04:00
}
2020-03-16 23:57:14 -04:00
}
2020-03-09 11:02:09 -04:00
2020-03-18 18:22:57 -04:00
// set to browser default which will be overridden
// by any future script loads (above)
KIRI . lang . set ( ) ;
2020-03-16 23:57:14 -04:00
// schedule init_one to run after all page content is loaded
2020-03-17 18:32:16 -04:00
// unless a languge script is loading first, in which case it
// will call init once it's done (or failed)
if ( ! lang _set ) {
2020-03-18 18:22:57 -04:00
if ( document . readyState === 'loading' ) {
SPACE . addEventListener ( DOC , 'DOMContentLoaded' , init _one ) ;
} else {
// happens in debug mode when scripts are chain loaded
init _one ( ) ;
}
2020-03-17 18:32:16 -04:00
}
2020-03-09 11:02:09 -04:00
} ) ( ) ;