fix origin for exports and imports in all cases. fix device name input. fix preserve item locations in non-fdm modes

This commit is contained in:
Stewart Allen 2020-03-03 20:06:10 -05:00
commit fdd2d16447
5 changed files with 86 additions and 55 deletions

View file

@ -1402,9 +1402,8 @@ var gs_kiri_cam = exports;
cmdSpindle = gcodes.gcodeSpindle || [ "M3 S{speed}" ], cmdSpindle = gcodes.gcodeSpindle || [ "M3 S{speed}" ],
cmdDwell = gcodes.gcodeDwell || [ "G4 P{time}" ], cmdDwell = gcodes.gcodeDwell || [ "G4 P{time}" ],
bounds = widget.getCamBounds(settings), bounds = widget.getCamBounds(settings),
bed = settings.device,
spro = settings.process, spro = settings.process,
sout = settings.process, dev = settings.device,
decimals = 4, decimals = 4,
pos = { x:null, y:null, z:null, f:null, t:null }, pos = { x:null, y:null, z:null, f:null, t:null },
line, line,
@ -1418,17 +1417,17 @@ var gs_kiri_cam = exports;
max: { x:-Infinity, y:-Infinity, z:-Infinity}, max: { x:-Infinity, y:-Infinity, z:-Infinity},
min: { x:Infinity, y:Infinity, z:Infinity} min: { x:Infinity, y:Infinity, z:Infinity}
}, },
offset = sout.outputOriginCenter ? null : { offset = {
x: bounds.max.x, //bed.bedWidth/2, x: -settings.origin.x,
y: bounds.max.y //bed.bedDepth/2 y: settings.origin.y
}, },
consts = { consts = {
tool: 0, tool: 0,
tool_name: "unknown", tool_name: "unknown",
top: offset ? bed.bedDepth : bed.bedDepth/2, top: offset ? dev.bedDepth : dev.bedDepth/2,
left: offset ? 0 : -bed.bedWidth/2, left: offset ? 0 : -dev.bedWidth/2,
right: offset ? bed.bedWidth : bed.bedWidth/2, right: offset ? dev.bedWidth : dev.bedWidth/2,
bottom: offset ? 0 : -bed.bedDepth/2, bottom: offset ? 0 : -dev.bedDepth/2,
time_sec: 0, time_sec: 0,
time_ms: 0, time_ms: 0,
time: 0 time: 0
@ -1572,9 +1571,9 @@ var gs_kiri_cam = exports;
point.x += offset.x; point.x += offset.x;
point.y += offset.y; point.y += offset.y;
} }
if (sout.outputInvertX) point.x = -point.x; if (spro.outputInvertX) point.x = -point.x;
if (sout.outputInvertY) point.y = -point.y; if (spro.outputInvertY) point.y = -point.y;
if (sout.camOriginTop) point.z = point.z - zmax; if (spro.camOriginTop) point.z = point.z - zmax;
}); });
}); });

View file

@ -47,6 +47,7 @@ var gs_kiri_print = exports;
this.output = []; this.output = [];
this.distance = 0; this.distance = 0;
this.bounds = null; this.bounds = null;
this.imported = null;
} }
PRO.addOutput = addOutput; PRO.addOutput = addOutput;
@ -84,6 +85,7 @@ var gs_kiri_print = exports;
}); });
output.push(seq); output.push(seq);
}); });
scope.imported = code;
scope.lines = lines.length; scope.lines = lines.length;
scope.bytes = code.length; scope.bytes = code.length;
}; };
@ -176,6 +178,7 @@ var gs_kiri_print = exports;
G0(); G0();
scope.imported = gcode;
scope.lines = lines.length; scope.lines = lines.length;
scope.bytes = gcode.length; scope.bytes = gcode.length;
}; };
@ -216,6 +219,10 @@ var gs_kiri_print = exports;
settings = scope.settings, settings = scope.settings,
mode = settings.mode; mode = settings.mode;
if (scope.imported) {
return ondone(scope.imported);
}
if (remote) { if (remote) {
// executed from kiri.js // executed from kiri.js
KIRI.work.printGCode(function(reply) { KIRI.work.printGCode(function(reply) {

View file

@ -39,6 +39,7 @@ self.kiri.license = exports.LICENSE;
bedRound: 1, bedRound: 1,
maxHeight: 1, maxHeight: 1,
extrudeAbs: 1, extrudeAbs: 1,
originCenter: 1,
filamentSize: 1, filamentSize: 1,
nozzleSize: 1, nozzleSize: 1,
gcodePre: 1, gcodePre: 1,
@ -117,6 +118,7 @@ self.kiri.license = exports.LICENSE;
bedWidth: 1, bedWidth: 1,
bedDepth: 1, bedDepth: 1,
bedHeight: 1, bedHeight: 1,
originCenter: 1,
spindleMax: 1, spindleMax: 1,
gcodePre: 1, gcodePre: 1,
gcodePost: 1, gcodePost: 1,
@ -213,6 +215,7 @@ self.kiri.license = exports.LICENSE;
{ name: "triangle" } { name: "triangle" }
], ],
// CAM only // CAM only
origin: {},
stock: {}, stock: {},
tools:[ tools:[
{ {
@ -254,7 +257,8 @@ self.kiri.license = exports.LICENSE;
bedWidth: 300, // FDM/CAM/Laser bedWidth: 300, // FDM/CAM/Laser
bedDepth: 175, // FDM/CAM/Laser bedDepth: 175, // FDM/CAM/Laser
bedHeight: 2.5, // display only (deprecate) bedHeight: 2.5, // display only (deprecate)
bedRound: false, // FDM bedRound: false, // FDM
originCenter: false,// FDM/CAM
maxHeight: 150, // FDM maxHeight: 150, // FDM
filamentSize: 1.75, // FDM filamentSize: 1.75, // FDM
nozzleSize: 0.4, // FDM nozzleSize: 0.4, // FDM
@ -541,6 +545,7 @@ self.kiri.license = exports.LICENSE;
camStock = null, camStock = null,
camTopZ = 0, camTopZ = 0,
topZ = 0, topZ = 0,
// origin = {x:0, y:0, z:0},
showFavorites = SDB['dev-favorites'] === 'true'; showFavorites = SDB['dev-favorites'] === 'true';
// seed defaults. will get culled on save // seed defaults. will get culled on save
@ -941,15 +946,12 @@ self.kiri.license = exports.LICENSE;
setOpacity(0); setOpacity(0);
currentPrint = kiri.newPrint(settings, []); currentPrint = kiri.newPrint(settings, []);
let center = settings.process.outputOriginCenter; let center = settings.process.outputOriginCenter;
let offset = center ? {x:0, y:0, z:camTopZ} : { let origin = settings.origin;
x: -settings.device.bedWidth / 2, let offset = {
y: -settings.device.bedDepth / 2, x: origin.x,
y: -origin.y,
z: origin.z
}; };
if (MODE === MODES.CAM && settings.stock.x && !center) {
offset.x = -settings.stock.x / 2;
offset.y = -settings.stock.y / 2;
offset.z = settings.stock.z;
}
switch (type) { switch (type) {
case 'svg': case 'svg':
currentPrint.parseSVG(code, offset); currentPrint.parseSVG(code, offset);
@ -964,18 +966,6 @@ self.kiri.license = exports.LICENSE;
UI.layerPrint.checked = true; UI.layerPrint.checked = true;
updateSliderMax(true); updateSliderMax(true);
showSlices(); showSlices();
switch (type) {
case 'svg':
currentPrint.exportGCode(false, gcode => {
// console.log({svg_to_gcode: gcode});
}, line => {
// console.log({gcode_line: line});
});
break;
default:
exportGCode(code);
break;
}
} }
function preparePrint(callback) { function preparePrint(callback) {
@ -1724,12 +1714,13 @@ self.kiri.license = exports.LICENSE;
// only auto-layout when in arrange mode // only auto-layout when in arrange mode
if (oldmode !== VIEWS.ARRANGE) { if (oldmode !== VIEWS.ARRANGE) {
SPACE.update(); return SPACE.update();
return;
} }
// do not layout when switching back from slice view // do not layout when switching back from slice view
if (!auto || (!space && !layout)) return SPACE.update(); if (!auto || (!space && !layout)) {
return SPACE.update();
}
// check if any widget has been modified // check if any widget has been modified
forAllWidgets(function(w) { forAllWidgets(function(w) {
@ -1918,8 +1909,10 @@ self.kiri.license = exports.LICENSE;
function updateCamStock(refresh) { function updateCamStock(refresh) {
let sd = settings.process; let sd = settings.process;
let offset = UI.camStockOffset.checked; let offset = UI.camStockOffset.checked;
let stockSet = sd.camStockX && sd.camStockY && sd.camStockZ;
camTopZ = topZ;
// create/inject cam stock if stock size other than default // create/inject cam stock if stock size other than default
if (MODE === MODES.CAM && sd.camStockX && sd.camStockY && sd.camStockZ && WIDGETS.length) { if (MODE === MODES.CAM && stockSet && WIDGETS.length) {
UI.stock.style.display = offset ? 'inline' : 'none'; UI.stock.style.display = offset ? 'inline' : 'none';
let csx = sd.camStockX; let csx = sd.camStockX;
let csy = sd.camStockY; let csy = sd.camStockY;
@ -2039,6 +2032,7 @@ self.kiri.license = exports.LICENSE;
oldWidgets.forEach(function(wid) { oldWidgets.forEach(function(wid) {
Widget.deleteFromState(wid); Widget.deleteFromState(wid);
}); });
alert2("workspace saved", 1);
} }
function loadFiles(files) { function loadFiles(files) {
@ -2088,10 +2082,6 @@ self.kiri.license = exports.LICENSE;
} }
function updateOrigin() { function updateOrigin() {
if (!settings.controller.showOrigin) {
SPACE.platform.setOrigin();
return;
}
let dev = settings.device; let dev = settings.device;
let proc = settings.process; let proc = settings.process;
let x = 0; let x = 0;
@ -2099,17 +2089,28 @@ self.kiri.license = exports.LICENSE;
let z = 0; let z = 0;
if (MODE === MODES.CAM && proc.camOriginTop) { if (MODE === MODES.CAM && proc.camOriginTop) {
z = camTopZ + 0.01; z = camTopZ + 0.01;
if (!camStock) {
z += proc.camZTopOffset;
}
} }
if (!proc.outputOriginCenter) { if (!proc.outputOriginCenter) {
if (camStock) { if (camStock) {
x = -camStock.scale.x / 2; x = (-camStock.scale.x / 2) + camStock.position.x;
y = camStock.scale.y / 2; y = (camStock.scale.y / 2) - camStock.position.y;
} else { } else {
x = -dev.bedWidth / 2; x = -dev.bedWidth / 2;
y = dev.bedDepth / 2; y = dev.bedDepth / 2;
} }
} else if (camStock) {
x = camStock.position.x;
y = -camStock.position.y;
}
settings.origin = {x, y, z};
if (settings.controller.showOrigin) {
SPACE.platform.setOrigin(x,y,z);
} else {
SPACE.platform.setOrigin();
} }
SPACE.platform.setOrigin(x,y,z);
} }
function updatePlatformSize() { function updatePlatformSize() {
@ -2132,7 +2133,7 @@ self.kiri.license = exports.LICENSE;
toload = ls2o('ws-widgets',[]), toload = ls2o('ws-widgets',[]),
newset = ls2o('ws-settings'), newset = ls2o('ws-settings'),
camera = ls2o('ws-camera'), camera = ls2o('ws-camera'),
isFDM = (newset || settings).mode === 'FDM'; position = true;
if (newset) { if (newset) {
fillMissingSettings(settingsDefault, newset); fillMissingSettings(settingsDefault, newset);
@ -2168,15 +2169,24 @@ self.kiri.license = exports.LICENSE;
forAllWidgets(function(widget) { forAllWidgets(function(widget) {
platformDelete(widget); platformDelete(widget);
}); });
toload.forEach(function(widgetid) { toload.forEach(function(widgetid) {
Widget.loadFromState(widgetid, function(widget) { Widget.loadFromState(widgetid, function(widget) {
if (widget) platformAdd(widget, 0, isFDM); if (widget) {
platformAdd(widget, 0, position);
}
if (++loaded === toload.length) { if (++loaded === toload.length) {
widgetDeselect(); widgetDeselect();
if (ondone) ondone(); if (ondone) {
ondone();
if ((newset || settings).mode != 'CAM') {
setTimeout(() => {
updateWidgetsTopZ();
SPACE.update();
}, 1);
};
}
} }
}, isFDM); }, position);
}); });
return toload.length > 0; return toload.length > 0;
@ -2249,7 +2259,7 @@ self.kiri.license = exports.LICENSE;
for (var k in load) { for (var k in load) {
if (!load.hasOwnProperty(k)) continue; if (!load.hasOwnProperty(k)) continue;
// prevent stored process from overwriting device defaults // prevent stored process from overwriting device defaults
if (k === "outputOriginCenter" && mode == "FDM") continue; //if (k === "outputOriginCenter" && mode == "FDM") continue;
settings.process[k] = load[k]; settings.process[k] = load[k];
} }
@ -2264,6 +2274,11 @@ self.kiri.license = exports.LICENSE;
$('selected-process').innerHTML = name; $('selected-process').innerHTML = name;
$('selected').style.display = (mode !== 'LASER') ? 'block' : 'none'; $('selected').style.display = (mode !== 'LASER') ? 'block' : 'none';
// FDM process settings overridden by device
if (mode == "FDM") {
settings.process.outputOriginCenter = (settings.device.originCenter || false);
}
updateFields(); updateFields();
if (!named) { if (!named) {
hideDialog(); hideDialog();
@ -2476,7 +2491,7 @@ self.kiri.license = exports.LICENSE;
UI.modeTable.style.display = lock ? 'none' : ''; UI.modeTable.style.display = lock ? 'none' : '';
if (camStock) camStock.material.visible = settings.mode === 'CAM'; if (camStock) camStock.material.visible = settings.mode === 'CAM';
restoreWorkspace(null,true); restoreWorkspace(null,true);
if (MODE !== MODES.FDM) layoutPlatform(); // if (MODE !== MODES.FDM) layoutPlatform();
if (then) then(); if (then) then();
triggerSettingsEvent(); triggerSettingsEvent();
} }
@ -2558,7 +2573,7 @@ self.kiri.license = exports.LICENSE;
deviceAll: $('device-all'), deviceAll: $('device-all'),
device: UC.newGroup("device", $('device')), device: UC.newGroup("device", $('device')),
deviceName: UC.newInput(LANG.dev_name, {size:20}), deviceName: UC.newInput(LANG.dev_name, {size:20, text:true}),
setDeviceFilament: UC.newInput(LANG.dev_fil, {title:LANG.dev_fil_desc, convert:UC.toFloat, modes:FDM}), setDeviceFilament: UC.newInput(LANG.dev_fil, {title:LANG.dev_fil_desc, convert:UC.toFloat, modes:FDM}),
setDeviceNozzle: UC.newInput(LANG.dev_nozl, {title:LANG.dev_nozl_desc, convert:UC.toFloat, modes:FDM}), setDeviceNozzle: UC.newInput(LANG.dev_nozl, {title:LANG.dev_nozl_desc, convert:UC.toFloat, modes:FDM}),
setDeviceWidth: UC.newInput(LANG.dev_bedw, {title:LANG.dev_bedw_desc, convert:UC.toInt}), setDeviceWidth: UC.newInput(LANG.dev_bedw, {title:LANG.dev_bedw_desc, convert:UC.toInt}),
@ -2909,6 +2924,10 @@ self.kiri.license = exports.LICENSE;
return active && (active.nodeName === "INPUT" || active.nodeName === "TEXTAREA"); return active && (active.nodeName === "INPUT" || active.nodeName === "TEXTAREA");
} }
function inputTextOK() {
return DOC.activeElement === UI.deviceName;
}
function textAreaHasFocus() { function textAreaHasFocus() {
var active = DOC.activeElement; var active = DOC.activeElement;
return active && active.nodeName === "TEXTAREA"; return active && active.nodeName === "TEXTAREA";
@ -2942,7 +2961,9 @@ self.kiri.license = exports.LICENSE;
} }
function keyDownHandler(evt) { function keyDownHandler(evt) {
if (modalShowing()) return false; if (modalShowing()) {
return false;
}
var move = evt.altKey ? 5 : 0, var move = evt.altKey ? 5 : 0,
deg = move ? 0 : -Math.PI / (evt.shiftKey ? 36 : 2); deg = move ? 0 : -Math.PI / (evt.shiftKey ? 36 : 2);
switch (evt.keyCode) { switch (evt.keyCode) {
@ -3016,7 +3037,9 @@ self.kiri.license = exports.LICENSE;
var handled = true, var handled = true,
style, sel, i, m, bb, style, sel, i, m, bb,
ncc = evt.charCode - 48; ncc = evt.charCode - 48;
if (modalShowing() || inputHasFocus()) return false; if (modalShowing() || inputHasFocus()) {
return false;
}
switch (evt.charCode) { switch (evt.charCode) {
case cca('`'): showSlices(0); break; case cca('`'): showSlices(0); break;
case cca('0'): showSlices(showLayerMax); break; case cca('0'): showSlices(showLayerMax); break;
@ -3353,6 +3376,7 @@ self.kiri.license = exports.LICENSE;
maxHeight: valueOf(set.build_height, 150), maxHeight: valueOf(set.build_height, 150),
nozzleSize: valueOf(set.nozzle_size, 0.4), nozzleSize: valueOf(set.nozzle_size, 0.4),
filamentSize: valueOf(set.filament_diameter, 1.75), filamentSize: valueOf(set.filament_diameter, 1.75),
originCenter: valueOf(set.origin_center, false),
extrudeAbs: valueOf(set.extrude_abs, false), extrudeAbs: valueOf(set.extrude_abs, false),
spindleMax: valueOf(set.spindle_max, 0), spindleMax: valueOf(set.spindle_max, 0),
gcodeFan: valueOf(cmd.fan_power, ''), gcodeFan: valueOf(cmd.fan_power, ''),

View file

@ -1,7 +1,7 @@
var exports = { var exports = {
COPYRIGHT:"Copyright (C) 2014-2019 Stewart Allen <sa@grid.space> - All Rights Reserved", COPYRIGHT:"Copyright (C) 2014-2019 Stewart Allen <sa@grid.space> - All Rights Reserved",
LICENSE:"See the license.md file included with the source distribution", LICENSE:"See the license.md file included with the source distribution",
VERSION:"1.6.6" VERSION:"1.6.7"
}; };
if (!module) var module = {}; if (!module) var module = {};
module.exports = exports; module.exports = exports;

View file

@ -282,6 +282,7 @@ var gs_moto_ui = exports;
ip.addEventListener('keydown', function(event) { ip.addEventListener('keydown', function(event) {
let key = event.key; let key = event.key;
if ( if (
options.text ||
(key >= '0' && key <= '9') || (key >= '0' && key <= '9') ||
key === '.' || key === '.' ||
key === '-' || key === '-' ||