Sane defaults for empty printer profile fields

This commit is contained in:
Gina Häußge 2016-09-19 14:35:04 +02:00
parent d017e507aa
commit 85e23c976b
2 changed files with 37 additions and 23 deletions

View file

@ -213,15 +213,30 @@ $(function() {
identifier = self.identifierPlaceholder();
}
var defaultProfile = cleanProfile();
var valid = function(value, f, def) {
var v = f(value);
if (isNaN(v)) {
return def;
}
return v;
};
var validFloat = function(value, def) {
return valid(value, parseFloat, def);
};
var validInt = function(value, def) {
return valid(value, parseInt, def);
};
var profile = {
id: identifier,
name: self.name(),
color: self.color(),
model: self.model(),
volume: {
width: parseFloat(self.volumeWidth()),
depth: parseFloat(self.volumeDepth()),
height: parseFloat(self.volumeHeight()),
width: validFloat(self.volumeWidth(), defaultProfile.volume.width),
depth: validFloat(self.volumeDepth(), defaultProfile.volume.depth),
height: validFloat(self.volumeHeight(), defaultProfile.volume.height),
formFactor: self.volumeFormFactor(),
origin: self.volumeOrigin()
},
@ -231,37 +246,36 @@ $(function() {
offsets: [
[0.0, 0.0]
],
nozzleDiameter: parseFloat(self.nozzleDiameter())
nozzleDiameter: validFloat(self.nozzleDiameter(), defaultProfile.extruder.nozzleDiameter)
},
axes: {
x: {
speed: parseInt(self.axisXSpeed()),
speed: validInt(self.axisXSpeed(), defaultProfile.axes.x.speed),
inverted: self.axisXInverted()
},
y: {
speed: parseInt(self.axisYSpeed()),
speed: validInt(self.axisYSpeed(), defaultProfile.axes.y.speed),
inverted: self.axisYInverted()
},
z: {
speed: parseInt(self.axisZSpeed()),
speed: validInt(self.axisZSpeed(), defaultProfile.axes.z.speed),
inverted: self.axisZInverted()
},
e: {
speed: parseInt(self.axisESpeed()),
speed: validInt(self.axisESpeed(), defaultProfile.axes.e.speed),
inverted: self.axisEInverted()
}
}
};
var offsetX, offsetY;
if (self.extruders() > 1) {
for (var i = 0; i < self.extruders() - 1; i++) {
var offset = [0.0, 0.0];
if (i < self.extruderOffsets().length) {
try {
offset = [parseFloat(self.extruderOffsets()[i]["x"]()), parseFloat(self.extruderOffsets()[i]["y"]())];
} catch (exc) {
log.error("Invalid offset in profile", identifier, "for extruder", i+1, ":", self.extruderOffsets()[i]["x"], ",", self.extruderOffsets()[i]["y"]);
}
offsetX = validFloat(self.extruderOffsets()[i]["x"](), 0.0);
offsetY = validFloat(self.extruderOffsets()[i]["y"](), 0.0);
offset = [offsetX, offsetY];
}
profile.extruder.offsets.push(offset);
}

View file

@ -49,21 +49,21 @@
<div class="controls form-inline">
<label>{{ _('X') }}</label>
<div class="input-append">
<input type="number" step="0.01" class="input-mini text-right" data-bind="value: volumeWidth">
<input type="number" step="0.01" class="input-mini text-right" data-bind="value: volumeWidth" placeholder="200">
<span class="add-on">mm</span>
</div>
</div>
<div class="controls form-inline">
<label>{{ _('Y') }}</label>
<div class="input-append">
<input type="number" step="0.01" class="input-mini text-right" data-bind="value: volumeDepth">
<input type="number" step="0.01" class="input-mini text-right" data-bind="value: volumeDepth" placeholder="200">
<span class="add-on">mm</span>
</div>
</div>
<div class="controls form-inline">
<label>{{ _('Z') }}</label>
<div class="input-append">
<input type="number" step="0.01" class="input-mini text-right" data-bind="value: volumeHeight">
<input type="number" step="0.01" class="input-mini text-right" data-bind="value: volumeHeight" placeholder="200">
<span class="add-on">mm</span>
</div>
</div>
@ -79,7 +79,7 @@
<div class="controls form-inline">
<label>{{ _('X') }}</label>
<div class="input-append">
<input type="number" class="input-mini text-right" data-bind="value: axisXSpeed">
<input type="number" class="input-mini text-right" data-bind="value: axisXSpeed" placeholder="6000">
<span class="add-on">mm/min</span>
</div>
<label class="checkbox">
@ -89,7 +89,7 @@
<div class="controls form-inline">
<label>{{ _('Y') }}</label>
<div class="input-append">
<input type="number" class="input-mini text-right" data-bind="value: axisYSpeed">
<input type="number" class="input-mini text-right" data-bind="value: axisYSpeed" placeholder="6000">
<span class="add-on">mm/min</span>
</div>
<label class="checkbox">
@ -99,7 +99,7 @@
<div class="controls form-inline">
<label>{{ _('Z') }}</label>
<div class="input-append">
<input type="number" class="input-mini text-right" data-bind="value: axisZSpeed">
<input type="number" class="input-mini text-right" data-bind="value: axisZSpeed" placeholder="200">
<span class="add-on">mm/min</span>
</div>
<label class="checkbox">
@ -109,7 +109,7 @@
<div class="controls form-inline">
<label>{{ _('E') }}</label>
<div class="input-append">
<input type="number" class="input-mini text-right" data-bind="value: axisESpeed">
<input type="number" class="input-mini text-right" data-bind="value: axisESpeed" placeholder="300">
<span class="add-on">mm/min</span>
</div>
</div>
@ -118,7 +118,7 @@
<label class="control-label">{{ _('Nozzle Diameter') }}</label>
<div class="controls">
<div class="input-append">
<input type="number" step="0.01" class="input-mini text-right" data-bind="value: nozzleDiameter">
<input type="number" step="0.01" class="input-mini text-right" data-bind="value: nozzleDiameter" placeholder="0.4">
<span class="add-on">mm</span>
</div>
</div>
@ -136,12 +136,12 @@
<label>T<span data-bind="text: idx"></span>:</label>
<label>X</label>
<div class="input-append">
<input type="number" step="0.01" class="input-mini text-right" data-bind="value: x">
<input type="number" step="0.01" class="input-mini text-right" data-bind="value: x" placeholder="0">
<span class="add-on">mm</span>
</div>
<label>Y</label>
<div class="input-append">
<input type="number" step="0.01" class="input-mini text-right" data-bind="value: y">
<input type="number" step="0.01" class="input-mini text-right" data-bind="value: y" placeholder="0">
<span class="add-on">mm</span>
</div>
</div>