better units / round handling. fix ruler in inches

This commit is contained in:
Stewart Allen 2021-01-10 19:10:55 -05:00
commit 2118098be9
5 changed files with 27 additions and 20 deletions

View file

@ -1499,8 +1499,8 @@
device: UC.newGroup(LANG.dv_gr_dev, $('device1'), {group:"ddev", inline:true, class:"noshow"}),
deviceName: UC.newInput(LANG.dv_name_s, {title:LANG.dv_name_l, size:"65%", text:true, action:updateDeviceName}),
bedWidth: UC.newInput(LANG.dv_bedw_s, {title:LANG.dv_bedw_l, convert:UC.toFloat, size:6, units:true}),
bedDepth: UC.newInput(LANG.dv_bedd_s, {title:LANG.dv_bedd_l, convert:UC.toFloat, size:6, units:true}),
bedWidth: UC.newInput(LANG.dv_bedw_s, {title:LANG.dv_bedw_l, convert:UC.toFloat, size:6, units:true, round:2}),
bedDepth: UC.newInput(LANG.dv_bedd_s, {title:LANG.dv_bedd_l, convert:UC.toFloat, size:6, units:true, round:2}),
maxHeight: UC.newInput(LANG.dv_bedh_s, {title:LANG.dv_bedh_l, convert:UC.toFloat, size:6, modes:FDM_SLA}),
spindleMax: UC.newInput(LANG.dv_spmx_s, {title:LANG.dv_spmx_l, convert:UC.toInt, size: 6, modes:CAM}),
deviceOrigin: UC.newBoolean(LANG.dv_orgc_s, onBooleanClick, {title:LANG.dv_orgc_l, modes:FDM_LASER_SLA}),

View file

@ -379,10 +379,13 @@
function toFloat() {
let nv = this.value !== '' ? parseFloat(this.value) : null;
if (nv !== null && this.bound) nv = this.bound(nv);
this.value = nv;
// this.value = nv;
if (this.setv) {
return this.real = nv * units;
};
return this.setv(nv * units);
// return this.real = (nv * units);
} else {
this.value = nv;
}
return nv;
}
@ -686,7 +689,7 @@
}
});
if (opt.units) {
addUnits(ip);
addUnits(ip, opt.round || 3);
}
}
if (!ip.convert) ip.convert = raw.bind(ip);
@ -695,15 +698,16 @@
return ip;
}
function addUnits(input) {
function addUnits(input, round) {
setters.push(input);
input.setv = function(value) {
if (typeof(value) === 'number') {
input.real = value;
input.value = value / units;
input.value = (value / units).round(round);
} else {
input.value = value;
}
return input.real;
};
return input;
}

View file

@ -34,7 +34,7 @@
restoreSupports(api.widgets.all());
});
api.event.on("settings.saved", (settings) => {
api.ui.fdmSupport.style.display = settings.device.bedBelt ? 'none' : 'flex';
api.ui.fdmSupport.style.display = lastMode === 'CAM' || settings.device.bedBelt ? 'none' : 'flex';
});
api.event.on("button.click", target => {
switch (target) {

View file

@ -415,6 +415,11 @@
}
}
function modMatch(val, mod) {
let mv = Math.abs(val) % mod;
return (mv < 1) || ((mod - mv) < 1);
}
function updateGrid() {
let { view, unitMinor, unitMajor, colorMajor, colorMinor } = grid;
let oldView = view;
@ -444,22 +449,22 @@
for (let x=0; x>x1; x -= unitMinor) {
let oh = isRound ? Math.sqrt(1-(x/xh)*(x/xh)) * yh : yh;
let arr = Math.abs(x % unitMajor) < 0.1 ? majors : minors;
let arr = modMatch(x, unitMajor) ? majors : minors;
arr.append({x:x-xo, y:-oh, z:zp}).append({x:x-xo, y:oh, z:zp});
}
for (let x=0; x<x2; x += unitMinor) {
let oh = isRound ? Math.sqrt(1-(x/xh)*(x/xh)) * yh : yh;
let arr = Math.abs(x % unitMajor) < 0.1 ? majors : minors;
let arr = modMatch(x, unitMajor) ? majors : minors;
arr.append({x:x-xo, y:-oh, z:zp}).append({x:x-xo, y:oh, z:zp});
}
for (let y=0; y>y1; y -= unitMinor) {
let ow = isRound ? Math.sqrt(1-(y/yh)*(y/yh)) * xh : xh;
let arr = Math.abs(y % unitMajor) < 0.1 ? majors : minors;
let arr = modMatch(y, unitMajor) ? majors : minors;
arr.append({x:-ow, y:y-yo, z:zp}).append({x:ow, y:y-yo, z:zp});
}
for (let y=0; y<y2; y += unitMinor) {
let ow = isRound ? Math.sqrt(1-(y/yh)*(y/yh)) * xh : xh;
let arr = Math.abs(y % unitMajor) < 0.1 ? majors : minors;
let arr = modMatch(y, unitMajor) ? majors : minors;
arr.append({x:-ow, y:y-yo, z:zp}).append({x:ow, y:y-yo, z:zp});
}