1 parent
bb63eaad03
commit
b9800bd71e
3 files changed
+92
-16
No files matched your search
@@ -645,6 +645,18 @@ class PrinterProfileManager:
|
||||
|
||||
value[path[-1]] = converter(value[path[-1]])
|
||||
|
||||
def validate_value(profile, path, validator):
|
||||
value = profile
|
||||
for part in path[:-1]:
|
||||
if not isinstance(value, dict) or part not in value:
|
||||
raise RuntimeError("%s is not contained in profile" % ".".join(path))
|
||||
value = value[part]
|
||||
|
||||
if not isinstance(value, dict) or path[-1] not in value:
|
||||
raise RuntimeError("%s is not contained in profile" % ".".join(path))
|
||||
|
||||
return validator(value[path[-1]])
|
||||
|
||||
# convert ints
|
||||
for path in (
|
||||
("extruder", "count"),
|
||||
@@ -696,6 +708,21 @@ class PrinterProfileManager:
|
||||
)
|
||||
return False
|
||||
|
||||
# validate volume size range
|
||||
for path in (
|
||||
("volume", "width"),
|
||||
("volume", "depth"),
|
||||
("volume", "height"),
|
||||
):
|
||||
if not validate_value(profile, path, lambda x: x > 0 and x < 10000):
|
||||
return False
|
||||
|
||||
# validate extruder count range
|
||||
if not validate_value(
|
||||
profile, ("extruder", "count"), lambda x: x > 0 and x < 100
|
||||
):
|
||||
return False
|
||||
|
||||
# validate form factor
|
||||
if profile["volume"]["formFactor"] not in BedFormFactor.values():
|
||||
self._logger.warning(
|
||||
|
||||
@@ -124,6 +124,14 @@ $(function () {
|
||||
return !self.name();
|
||||
});
|
||||
|
||||
self.sizeInvalid = ko.pureComputed(function () {
|
||||
return (
|
||||
!(self.volumeWidth() > 0 && self.volumeWidth() < 10000) ||
|
||||
!(self.volumeDepth() > 0 && self.volumeDepth() < 10000) ||
|
||||
!(self.volumeHeight() > 0 && self.volumeHeight() < 10000)
|
||||
);
|
||||
});
|
||||
|
||||
self.identifierInvalid = ko.pureComputed(function () {
|
||||
var identifier = self.identifier();
|
||||
var placeholder = self.identifierPlaceholder();
|
||||
@@ -165,7 +173,9 @@ $(function () {
|
||||
});
|
||||
|
||||
self.valid = function () {
|
||||
return !self.nameInvalid() && !self.identifierInvalid();
|
||||
return (
|
||||
!self.nameInvalid() && !self.identifierInvalid() && !self.sizeInvalid()
|
||||
);
|
||||
};
|
||||
|
||||
self.availableColors = ko.observable([
|
||||
@@ -273,11 +283,32 @@ $(function () {
|
||||
}
|
||||
return v;
|
||||
};
|
||||
var validFloat = function (value, def) {
|
||||
return valid(value, parseFloat, def);
|
||||
var runChecks = function (value, def, checks) {
|
||||
if (checks.gt !== undefined) {
|
||||
if (!(value > checks.gt)) {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
if (checks.lt !== undefined) {
|
||||
if (!(value < checks.gt)) {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
};
|
||||
var validInt = function (value, def) {
|
||||
return valid(value, parseInt, def);
|
||||
var validFloat = function (value, def, checks) {
|
||||
var v = valid(value, parseFloat, def);
|
||||
if (checks) {
|
||||
v = runChecks(value, def, checks);
|
||||
}
|
||||
return v;
|
||||
};
|
||||
var validInt = function (value, def, checks) {
|
||||
var v = valid(value, parseInt, def);
|
||||
if (checks) {
|
||||
v = runChecks(value, def, checks);
|
||||
}
|
||||
return v;
|
||||
};
|
||||
|
||||
var profile = {
|
||||
@@ -286,16 +317,26 @@ $(function () {
|
||||
color: self.color(),
|
||||
model: self.model(),
|
||||
volume: {
|
||||
width: validFloat(self.volumeWidth(), defaultProfile.volume.width),
|
||||
depth: validFloat(self.volumeDepth(), defaultProfile.volume.depth),
|
||||
height: validFloat(self.volumeHeight(), defaultProfile.volume.height),
|
||||
width: validFloat(self.volumeWidth(), defaultProfile.volume.width, {
|
||||
gt: 0,
|
||||
lt: 10000
|
||||
}),
|
||||
depth: validFloat(self.volumeDepth(), defaultProfile.volume.depth, {
|
||||
gt: 0,
|
||||
lt: 10000
|
||||
}),
|
||||
height: validFloat(
|
||||
self.volumeHeight(),
|
||||
defaultProfile.volume.height,
|
||||
{gt: 0, lt: 10000}
|
||||
),
|
||||
formFactor: self.volumeFormFactor(),
|
||||
origin: self.volumeOrigin()
|
||||
},
|
||||
heatedBed: self.heatedBed(),
|
||||
heatedChamber: self.heatedChamber(),
|
||||
extruder: {
|
||||
count: parseInt(self.extruders()),
|
||||
count: runChecks(parseInt(self.extruders()), 1, {gt: 0, lt: 100}),
|
||||
offsets: [[0.0, 0.0]],
|
||||
nozzleDiameter: validFloat(
|
||||
self.nozzleDiameter(),
|
||||
@@ -309,19 +350,27 @@ $(function () {
|
||||
},
|
||||
axes: {
|
||||
x: {
|
||||
speed: validInt(self.axisXSpeed(), defaultProfile.axes.x.speed),
|
||||
speed: validInt(self.axisXSpeed(), defaultProfile.axes.x.speed, {
|
||||
gt: 0
|
||||
}),
|
||||
inverted: self.axisXInverted()
|
||||
},
|
||||
y: {
|
||||
speed: validInt(self.axisYSpeed(), defaultProfile.axes.y.speed),
|
||||
speed: validInt(self.axisYSpeed(), defaultProfile.axes.y.speed, {
|
||||
gt: 0
|
||||
}),
|
||||
inverted: self.axisYInverted()
|
||||
},
|
||||
z: {
|
||||
speed: validInt(self.axisZSpeed(), defaultProfile.axes.z.speed),
|
||||
speed: validInt(self.axisZSpeed(), defaultProfile.axes.z.speed, {
|
||||
gt: 0
|
||||
}),
|
||||
inverted: self.axisZInverted()
|
||||
},
|
||||
e: {
|
||||
speed: validInt(self.axisESpeed(), defaultProfile.axes.e.speed),
|
||||
speed: validInt(self.axisESpeed(), defaultProfile.axes.e.speed, {
|
||||
gt: 0
|
||||
}),
|
||||
inverted: self.axisEInverted()
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -41,7 +41,7 @@
|
||||
<label class="control-label">{{ _('Width (X)') }}</label>
|
||||
<div class="controls">
|
||||
<div class="input-append">
|
||||
<input type="number" step="0.01" class="input-mini text-right" data-bind="value: volumeWidth" placeholder="200">
|
||||
<input type="number" step="0.01" min="1" max="9999" class="input-mini text-right" data-bind="value: volumeWidth, valueUpdate: 'input'" placeholder="200">
|
||||
<span class="add-on">mm</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -50,7 +50,7 @@
|
||||
<label class="control-label">{{ _('Depth (Y)') }}</label>
|
||||
<div class="controls">
|
||||
<div class="input-append">
|
||||
<input type="number" step="0.01" class="input-mini text-right" data-bind="value: volumeDepth" placeholder="200">
|
||||
<input type="number" step="0.01" min="1" max="9999" class="input-mini text-right" data-bind="value: volumeDepth, valueUpdate: 'input'" placeholder="200">
|
||||
<span class="add-on">mm</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -61,7 +61,7 @@
|
||||
<label class="control-label">{{ _('Diameter (X/Y)') }}</label>
|
||||
<div class="controls">
|
||||
<div class="input-append">
|
||||
<input type="number" step="0.01" class="input-mini text-right" data-bind="value: volumeWidth" placeholder="200">
|
||||
<input type="number" step="0.01" min="1" max="9999" class="input-mini text-right" data-bind="value: volumeWidth, valueUpdate: 'input'" placeholder="200">
|
||||
<span class="add-on">mm</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user