Merge branch 'maintenance' into devel
# Conflicts: # AUTHORS.md # src/octoprint/plugin/__init__.py # src/octoprint/server/__init__.py # src/octoprint/server/api/__init__.py # tests/timelapse/test_timelapse_helpers.py
This commit is contained in:
commit
fd4ff2bf37
23 files changed
+457
-230
No files matched your search
+3
-3
@@ -24,10 +24,10 @@ maintenance 1.3.10 fdf0f75ffa5731fee406c6e761e84a9d2b47aa43 pep440-dev
|
||||
fix/.* 1.3.10 fdf0f75ffa5731fee406c6e761e84a9d2b47aa43 pep440-dev
|
||||
improve/.* 1.3.10 fdf0f75ffa5731fee406c6e761e84a9d2b47aa43 pep440-dev
|
||||
|
||||
# staging/maintenance is currently the branch for preparation of 1.3.9rc2
|
||||
# staging/maintenance is currently the branch for preparation of 1.3.9rc4
|
||||
# so is regressionfix/...
|
||||
staging/maintenance 1.3.9rc3 fd94fc94a09dd91deeb2f59a6b3b00b37eb1f145 pep440-dev
|
||||
regressionfix/.* 1.3.9rc3 fd94fc94a09dd91deeb2f59a6b3b00b37eb1f145 pep440-dev
|
||||
staging/maintenance 1.3.9rc4 2806676707020b270097876d6189d3c484dd47b8 pep440-dev
|
||||
regressionfix/.* 1.3.9rc4 2806676707020b270097876d6189d3c484dd47b8 pep440-dev
|
||||
|
||||
# every other branch is a development branch and thus gets resolved to 1.4.0-dev for now
|
||||
.* 1.4.0 7f5d03d0549bcbd26f40e7e4a3297ea5204fb1cc pep440-dev
|
||||
@@ -93,6 +93,7 @@ date of first contribution):
|
||||
* [Sven Lohrmann](https://github.com/malnvenshorn)
|
||||
* [Andy Castille](https://github.com/klikini)
|
||||
* [Zachary Nofzinger](https://github.com/ZachNo)
|
||||
* [Brad Fisher](https://github.com/bradcfisher)
|
||||
|
||||
OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by
|
||||
[Daid Braam](https://github.com/daid). Parts of its communication layer and
|
||||
|
||||
@@ -1,11 +1,27 @@
|
||||
# OctoPrint Changelog
|
||||
|
||||
## 1.3.9rc3 (2018-07-16)
|
||||
|
||||
### Improvements
|
||||
|
||||
* Fix resend and timeout handling during an active `job_on_hold`.
|
||||
|
||||
### Bug fixes
|
||||
|
||||
* [#2677](https://github.com/foosel/OctoPrint/issues/2677) (regression) - Fix a deadlock when `job_on_hold` is utilized (causing issues at least with Octolapse)
|
||||
* [#2719](https://github.com/foosel/OctoPrint/issues/2719) (regression) - Fix live print time estimation
|
||||
|
||||
### More information
|
||||
|
||||
* [Commits](https://github.com/foosel/OctoPrint/compare/1.3.9rc2...1.3.9rc3)
|
||||
|
||||
## 1.3.9rc2 (2018-07-06)
|
||||
|
||||
### Improvements
|
||||
|
||||
* Add sanity check for disabled plugin list (see also [#2687 (comment)](https://github.com/foosel/OctoPrint/issues/2687#issuecomment-399797596)).
|
||||
* Improve logging of exceptions triggered inside the state update worker (see also [#2715](https://github.com/foosel/OctoPrint/issues/2715)).
|
||||
* Workaround for a potential `pip` issue when updating components through the Software Update plugin.
|
||||
|
||||
### Bug fixes
|
||||
|
||||
|
||||
+2
-1
@@ -28,6 +28,7 @@ thanks to everyone who contributed!
|
||||
* Jeff Renfer
|
||||
* Jefferson Hunt
|
||||
* Jeremiah Avery
|
||||
* Joseph Payne
|
||||
* Josh Daniels
|
||||
* Joshua Wills
|
||||
* Justin Kaufman
|
||||
@@ -59,4 +60,4 @@ thanks to everyone who contributed!
|
||||
* Timothy D Hoogland
|
||||
* Trent Shumay
|
||||
|
||||
and 1332 more wonderful people pledging on the [Patreon campaign](https://patreon.com/foosel)!
|
||||
and 1333 more wonderful people pledging on the [Patreon campaign](https://patreon.com/foosel)!
|
||||
@@ -1134,6 +1134,32 @@ octoprint.server.http.routes
|
||||
:return: a list of 3-tuples with additional routes as defined above
|
||||
:rtype: list
|
||||
|
||||
.. _sec-plugins-hook-timelapse-extensions:
|
||||
|
||||
octoprint.timelapse.extensions
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. py:function:: timelapse_extension_hook(*args, **kwargs)
|
||||
|
||||
Allows extending the set of supported file extensions for timelapse files. Handlers must return a list of
|
||||
additional file extensions.
|
||||
|
||||
**Example**
|
||||
|
||||
Allow the management of timelapse GIFs with extension ``gif``.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
def get_timelapse_extensions(*args, **kwargs):
|
||||
return ["gif"]
|
||||
|
||||
__plugin_hooks__ = {
|
||||
"octoprint.timelapse.extensions": get_timelapse_extensions
|
||||
}
|
||||
|
||||
:return: a list of additional file extensions
|
||||
:rtype: list
|
||||
|
||||
.. _sec-plugins-hook-ui-web-templatetypes:
|
||||
|
||||
octoprint.ui.web.templatetypes
|
||||
|
||||
@@ -31,8 +31,7 @@ INSTALL_REQUIRES = [
|
||||
"pyserial>=3.4,<3.5",
|
||||
"netaddr>=0.7.19,<0.8",
|
||||
"watchdog>=0.8.3,<0.9",
|
||||
"sarge==0.1.4", # 0.1.5 introduced a breaking change with regards to the async keyword. Pinning
|
||||
# to 0.1.4 for now to work around this.
|
||||
"sarge==0.1.5",
|
||||
"netifaces>=0.10.6,<0.11",
|
||||
"pylru>=1.0.9,<1.1",
|
||||
"rsa>=3.4,<3.5",
|
||||
|
||||
@@ -71,3 +71,6 @@ def gcode_command(path, speedx, speedy, speedz, offset, maxt, throttle, throttle
|
||||
click.echo("DONE:{}s".format(time.time() - start_time))
|
||||
click.echo("RESULTS:")
|
||||
click.echo(yaml.safe_dump(interpreter.get_result(), default_flow_style=False, indent=" ", allow_unicode=True))
|
||||
|
||||
if __name__ == "__main__":
|
||||
gcode_command()
|
||||
@@ -364,7 +364,7 @@ class GcodeAnalysisQueue(AbstractAnalysisQueue):
|
||||
self._logger.info("Invoking analysis command: {}".format(" ".join(command)))
|
||||
|
||||
self._aborted = False
|
||||
p = sarge.run(command, async=True, stdout=sarge.Capture())
|
||||
p = sarge.run(command, async_=True, stdout=sarge.Capture())
|
||||
|
||||
while len(p.commands) == 0:
|
||||
# somewhat ugly... we can't use wait_events because
|
||||
|
||||
@@ -95,7 +95,8 @@ def plugin_manager(init=False, plugin_folders=None, plugin_bases=None, plugin_en
|
||||
if plugin_restart_needing_hooks is None:
|
||||
plugin_restart_needing_hooks = ["octoprint.server.http.*",
|
||||
"octoprint.printer.factory",
|
||||
"octoprint.access.permissions"]
|
||||
"octoprint.access.permissions",
|
||||
"octoprint.timelapse.extensions"]
|
||||
|
||||
if plugin_obsolete_hooks is None:
|
||||
plugin_obsolete_hooks = ["octoprint.comm.protocol.gcode"]
|
||||
|
||||
@@ -312,7 +312,7 @@ class CuraPlugin(octoprint.plugin.SlicerPlugin,
|
||||
working_dir))
|
||||
|
||||
import sarge
|
||||
p = sarge.run(args, cwd=working_dir, async=True, stdout=sarge.Capture(), stderr=sarge.Capture())
|
||||
p = sarge.run(args, cwd=working_dir, async_=True, stdout=sarge.Capture(), stderr=sarge.Capture())
|
||||
p.wait_events()
|
||||
self._slicing_commands[machinecode_path] = p.commands[0]
|
||||
|
||||
|
||||
@@ -601,8 +601,14 @@ class DiscoveryPlugin(octoprint.plugin.StartupPlugin,
|
||||
alive message
|
||||
"""
|
||||
|
||||
from BaseHTTPServer import BaseHTTPRequestHandler
|
||||
from StringIO import StringIO
|
||||
try:
|
||||
# noinspection PyCompatibility
|
||||
from http.server import BaseHTTPRequestHandler
|
||||
except ImportError:
|
||||
# noinspection PyCompatibility
|
||||
from BaseHTTPServer import BaseHTTPRequestHandler
|
||||
|
||||
from io import BytesIO
|
||||
import socket
|
||||
|
||||
socket.setdefaulttimeout(timeout)
|
||||
@@ -617,8 +623,9 @@ class DiscoveryPlugin(octoprint.plugin.StartupPlugin,
|
||||
|
||||
class Request(BaseHTTPRequestHandler):
|
||||
|
||||
# noinspection PyMissingConstructor
|
||||
def __init__(self, request_text):
|
||||
self.rfile = StringIO(request_text)
|
||||
self.rfile = BytesIO(request_text)
|
||||
self.raw_requestline = self.rfile.readline()
|
||||
self.error_code = self.error_message = None
|
||||
self.parse_request()
|
||||
|
||||
@@ -127,7 +127,7 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin,
|
||||
self._console_logger.propagate = False
|
||||
|
||||
# decouple repository fetching from server startup
|
||||
self._fetch_all_data(async=True)
|
||||
self._fetch_all_data(do_async=True)
|
||||
|
||||
##~~ SettingsPlugin
|
||||
|
||||
@@ -224,7 +224,7 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin,
|
||||
from octoprint.events import Events
|
||||
if event != Events.CONNECTIVITY_CHANGED or not payload or not payload.get("new", False):
|
||||
return
|
||||
self._fetch_all_data(async=True)
|
||||
self._fetch_all_data(do_async=True)
|
||||
|
||||
##~~ SimpleApiPlugin
|
||||
|
||||
@@ -738,12 +738,12 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin,
|
||||
self._event_bus.fire("plugin_pluginmanager_disableplugin", dict(id=plugin.key,
|
||||
version=plugin.version))
|
||||
|
||||
def _fetch_all_data(self, async=False):
|
||||
def _fetch_all_data(self, do_async=False):
|
||||
def run():
|
||||
self._repository_available = self._fetch_repository_from_disk()
|
||||
self._notices_available = self._fetch_notices_from_disk()
|
||||
|
||||
if async:
|
||||
if do_async:
|
||||
thread = threading.Thread(target=run)
|
||||
thread.daemon = True
|
||||
thread.start()
|
||||
|
||||
@@ -997,7 +997,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
|
||||
|
||||
self._logger.info("Restarting...")
|
||||
try:
|
||||
util.execute(restart_command, evaluate_returncode=False, async=True)
|
||||
util.execute(restart_command, evaluate_returncode=False, do_async=True)
|
||||
except exceptions.ScriptError as e:
|
||||
self._logger.exception("Error while restarting via command {}".format(restart_command))
|
||||
self._logger.warn("Restart stdout:\n{}".format(e.stdout))
|
||||
|
||||
@@ -59,7 +59,9 @@ def _execute(command, **kwargs):
|
||||
joined_command = command
|
||||
_log_call(joined_command)
|
||||
|
||||
kwargs.update(dict(async=True, stdout=sarge.Capture(), stderr=sarge.Capture()))
|
||||
kwargs.update(dict(async_=True,
|
||||
stdout=sarge.Capture(),
|
||||
stderr=sarge.Capture()))
|
||||
|
||||
try:
|
||||
p = sarge.run(command, **kwargs)
|
||||
|
||||
@@ -9,12 +9,14 @@ __copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms
|
||||
from .exceptions import ScriptError
|
||||
|
||||
|
||||
def execute(command, cwd=None, evaluate_returncode=True, async=False):
|
||||
def execute(command, cwd=None, evaluate_returncode=True, **kwargs):
|
||||
do_async = kwargs.get("do_async", kwargs.get("async", False))
|
||||
|
||||
import sarge
|
||||
p = None
|
||||
|
||||
try:
|
||||
p = sarge.run(command, cwd=cwd, stdout=sarge.Capture(), stderr=sarge.Capture(), async=async)
|
||||
p = sarge.run(command, cwd=cwd, stdout=sarge.Capture(), stderr=sarge.Capture(), async_=do_async)
|
||||
except:
|
||||
returncode = p.returncode if p is not None else None
|
||||
stdout = p.stdout.text if p is not None and p.stdout is not None else ""
|
||||
|
||||
@@ -536,6 +536,7 @@ class Server(object):
|
||||
self._setup_assets()
|
||||
|
||||
# configure timelapse
|
||||
octoprint.timelapse.valid_timelapse("test")
|
||||
octoprint.timelapse.configure_timelapse()
|
||||
|
||||
# setup command triggers
|
||||
@@ -584,6 +585,8 @@ class Server(object):
|
||||
|
||||
no_hidden_files_validator = dict(path_validation=util.tornado.path_validation_factory(lambda path: not octoprint.util.is_hidden_path(path),
|
||||
status_code=404))
|
||||
timelapse_validator = dict(path_validation=util.tornado.path_validation_factory(lambda path: not octoprint.util.is_hidden_path(path) and octoprint.timelapse.valid_timelapse(path),
|
||||
status_code=404))
|
||||
|
||||
def joined_dict(*dicts):
|
||||
if not len(dicts):
|
||||
@@ -599,10 +602,10 @@ class Server(object):
|
||||
server_routes = self._router.urls + [
|
||||
# various downloads
|
||||
# .mpg and .mp4 timelapses:
|
||||
(r"/downloads/timelapse/([^/]*\.m(.*))", util.tornado.LargeResponseHandler, joined_dict(dict(path=self._settings.getBaseFolder("timelapse")),
|
||||
timelapse_permission_validator,
|
||||
download_handler_kwargs,
|
||||
no_hidden_files_validator)),
|
||||
(r"/downloads/timelapse/(.*)", util.tornado.LargeResponseHandler, joined_dict(dict(path=self._settings.getBaseFolder("timelapse")),
|
||||
timelapse_permission_validator,
|
||||
download_handler_kwargs,
|
||||
timelapse_validator)),
|
||||
(r"/downloads/files/local/(.*)", util.tornado.LargeResponseHandler, joined_dict(dict(path=self._settings.getBaseFolder("uploads"),
|
||||
as_attachment=True,
|
||||
name_generator=download_name_generator),
|
||||
|
||||
@@ -132,15 +132,17 @@ def downloadTimelapse(filename):
|
||||
@require_firstrun
|
||||
@Permissions.TIMELAPSE_DELETE.require(403)
|
||||
def deleteTimelapse(filename):
|
||||
if util.is_allowed_file(filename, ["mpg", "mpeg", "mp4", "m4v", "mkv"]):
|
||||
timelapse_folder = settings().getBaseFolder("timelapse")
|
||||
full_path = os.path.realpath(os.path.join(timelapse_folder, filename))
|
||||
if full_path.startswith(timelapse_folder) and os.path.exists(full_path):
|
||||
try:
|
||||
os.remove(full_path)
|
||||
except Exception as ex:
|
||||
logging.getLogger(__file__).exception("Error deleting timelapse file {}".format(full_path))
|
||||
return make_response("Unexpected error: {}".format(ex), 500)
|
||||
timelapse_folder = settings().getBaseFolder("timelapse")
|
||||
full_path = os.path.realpath(os.path.join(timelapse_folder, filename))
|
||||
if octoprint.timelapse.valid_timelapse(full_path) \
|
||||
and full_path.startswith(timelapse_folder) \
|
||||
and os.path.exists(full_path) \
|
||||
and not util.is_hidden_path(full_path):
|
||||
try:
|
||||
os.remove(full_path)
|
||||
except Exception as ex:
|
||||
logging.getLogger(__file__).exception("Error deleting timelapse file {}".format(full_path))
|
||||
return make_response("Unexpected error: {}".format(ex), 500)
|
||||
|
||||
return getTimelapseData()
|
||||
|
||||
|
||||
@@ -10,7 +10,11 @@ GCODE.renderer = (function(){
|
||||
// ***** PRIVATE ******
|
||||
var canvas;
|
||||
var ctx;
|
||||
var zoomFactor= 2.8, zoomFactorDelta = 0.4;
|
||||
|
||||
var viewportChanged = true;
|
||||
var lineWidthFactor = 1 / 2.8;
|
||||
|
||||
var zoomFactorDelta = 0.4;
|
||||
var gridStep=10;
|
||||
var ctxHeight, ctxWidth;
|
||||
var prevX=0, prevY=0;
|
||||
@@ -18,7 +22,7 @@ GCODE.renderer = (function(){
|
||||
|
||||
var layerNumStore, progressStore={from: 0, to: -1};
|
||||
var lastX, lastY;
|
||||
var dragStart, dragged;
|
||||
var dragStart;
|
||||
var scaleFactor = 1.1;
|
||||
var model = undefined;
|
||||
var modelInfo = undefined;
|
||||
@@ -56,7 +60,12 @@ GCODE.renderer = (function(){
|
||||
bed: {x: 200, y: 200},
|
||||
container: undefined,
|
||||
|
||||
onInternalOptionChange: undefined
|
||||
onInternalOptionChange: undefined,
|
||||
|
||||
onViewportChange: undefined,
|
||||
onDragStart: undefined, // Cancellable (return false)
|
||||
onDrag: undefined, // Cancellable (return false)
|
||||
onDragStop: undefined
|
||||
};
|
||||
|
||||
var offsetModelX = 0, offsetModelY = 0;
|
||||
@@ -66,19 +75,37 @@ GCODE.renderer = (function(){
|
||||
var speedsByLayer = {};
|
||||
var currentInvertX = false, currentInvertY = false;
|
||||
|
||||
function notifyIfViewportChanged() {
|
||||
if (viewportChanged) {
|
||||
if (renderOptions["onViewportChange"]) {
|
||||
renderOptions["onViewportChange"](ctx.getTransform());
|
||||
}
|
||||
viewportChanged = false;
|
||||
}
|
||||
}
|
||||
|
||||
var reRender = function(){
|
||||
notifyIfViewportChanged();
|
||||
|
||||
var p1 = ctx.transformedPoint(0,0);
|
||||
var p2 = ctx.transformedPoint(canvas.width,canvas.height);
|
||||
ctx.clearRect(p1.x,p1.y,p2.x-p1.x,p2.y-p1.y);
|
||||
|
||||
drawGrid();
|
||||
drawBoundingBox();
|
||||
if (renderOptions['showNextLayer'] && model && model.length && layerNumStore < model.length - 1) {
|
||||
drawLayer(layerNumStore + 1, 0, GCODE.renderer.getLayerNumSegments(layerNumStore + 1), true);
|
||||
if (model && model.length) {
|
||||
if (layerNumStore < model.length) {
|
||||
if (renderOptions['showNextLayer'] && layerNumStore < model.length - 1) {
|
||||
drawLayer(layerNumStore + 1, 0, GCODE.renderer.getLayerNumSegments(layerNumStore + 1), true);
|
||||
}
|
||||
if (renderOptions['showPreviousLayer'] && layerNumStore > 0) {
|
||||
drawLayer(layerNumStore - 1, 0, GCODE.renderer.getLayerNumSegments(layerNumStore - 1), true);
|
||||
}
|
||||
drawLayer(layerNumStore, progressStore.from, progressStore.to);
|
||||
} else {
|
||||
console.log("Got request to render non-existent layer");
|
||||
}
|
||||
}
|
||||
if (renderOptions['showPreviousLayer'] && layerNumStore > 0) {
|
||||
drawLayer(layerNumStore - 1, 0, GCODE.renderer.getLayerNumSegments(layerNumStore - 1), true);
|
||||
}
|
||||
drawLayer(layerNumStore, progressStore.from, progressStore.to);
|
||||
};
|
||||
|
||||
function trackTransforms(ctx){
|
||||
@@ -95,22 +122,26 @@ GCODE.renderer = (function(){
|
||||
var restore = ctx.restore;
|
||||
ctx.restore = function(){
|
||||
xform = savedTransforms.pop();
|
||||
viewportChanged = true;
|
||||
return restore.call(ctx);
|
||||
};
|
||||
|
||||
var scale = ctx.scale;
|
||||
ctx.scale = function(sx,sy){
|
||||
xform = xform.scaleNonUniform(sx,sy);
|
||||
viewportChanged = true;
|
||||
return scale.call(ctx,sx,sy);
|
||||
};
|
||||
var rotate = ctx.rotate;
|
||||
ctx.rotate = function(radians){
|
||||
xform = xform.rotate(radians*180/Math.PI);
|
||||
viewportChanged = true;
|
||||
return rotate.call(ctx,radians);
|
||||
};
|
||||
var translate = ctx.translate;
|
||||
ctx.translate = function(dx,dy){
|
||||
xform = xform.translate(dx,dy);
|
||||
viewportChanged = true;
|
||||
return translate.call(ctx,dx,dy);
|
||||
};
|
||||
var transform = ctx.transform;
|
||||
@@ -118,6 +149,7 @@ GCODE.renderer = (function(){
|
||||
var m2 = svg.createSVGMatrix();
|
||||
m2.a=a; m2.b=b; m2.c=c; m2.d=d; m2.e=e; m2.f=f;
|
||||
xform = xform.multiply(m2);
|
||||
viewportChanged = true;
|
||||
return transform.call(ctx,a,b,c,d,e,f);
|
||||
};
|
||||
var setTransform = ctx.setTransform;
|
||||
@@ -128,6 +160,7 @@ GCODE.renderer = (function(){
|
||||
xform.d = d;
|
||||
xform.e = e;
|
||||
xform.f = f;
|
||||
viewportChanged = true;
|
||||
return setTransform.call(ctx,a,b,c,d,e,f);
|
||||
};
|
||||
var pt = svg.createSVGPoint();
|
||||
@@ -152,10 +185,12 @@ GCODE.renderer = (function(){
|
||||
ctxWidth = canvas.width;
|
||||
lastX = ctxWidth/2;
|
||||
lastY = ctxHeight/2;
|
||||
ctx.lineWidth = 2;
|
||||
ctx.lineWidth = 2 * lineWidthFactor;
|
||||
ctx.lineCap = 'round';
|
||||
trackTransforms(ctx);
|
||||
|
||||
ctx.scale(1,-1); // Invert y-axis
|
||||
|
||||
// dragging => translating
|
||||
canvas.addEventListener('mousedown', function(event){
|
||||
document.body.style.mozUserSelect = document.body.style.webkitUserSelect = document.body.style.userSelect = 'none';
|
||||
@@ -163,10 +198,10 @@ GCODE.renderer = (function(){
|
||||
// remember starting point of dragging gesture
|
||||
lastX = (event.offsetX || (event.pageX - canvas.offsetLeft)) * pixelRatio;
|
||||
lastY = (event.offsetY || (event.pageY - canvas.offsetTop)) * pixelRatio;
|
||||
dragStart = ctx.transformedPoint(lastX, lastY);
|
||||
|
||||
// not yet dragged anything
|
||||
dragged = false;
|
||||
var pt = ctx.transformedPoint(lastX, lastY);
|
||||
if (!renderOptions["onDragStart"] || (renderOptions["onDragStart"](pt) !== false))
|
||||
dragStart = pt;
|
||||
}, false);
|
||||
|
||||
canvas.addEventListener('mousemove', function(event){
|
||||
@@ -175,11 +210,13 @@ GCODE.renderer = (function(){
|
||||
lastY = (event.offsetY || (event.pageY - canvas.offsetTop)) * pixelRatio;
|
||||
|
||||
// mouse movement => dragged
|
||||
dragged = true;
|
||||
|
||||
if (dragStart !== undefined){
|
||||
if (dragStart !== undefined) {
|
||||
// translate
|
||||
var pt = ctx.transformedPoint(lastX,lastY);
|
||||
|
||||
if (renderOptions["onDrag"] && (renderOptions["onDrag"](pt) === false))
|
||||
return;
|
||||
|
||||
ctx.translate(pt.x - dragStart.x, pt.y - dragStart.y);
|
||||
reRender();
|
||||
|
||||
@@ -207,6 +244,12 @@ GCODE.renderer = (function(){
|
||||
canvas.addEventListener('mouseup', function(event){
|
||||
// reset dragStart
|
||||
dragStart = undefined;
|
||||
|
||||
if (renderOptions["onDragStop"]) {
|
||||
var x = (event.offsetX || (event.pageX - canvas.offsetLeft)) * pixelRatio;
|
||||
var y = (event.offsetY || (event.pageY - canvas.offsetTop)) * pixelRatio;
|
||||
renderOptions["onDragStop"](ctx.transformedPoint(x,y));
|
||||
}
|
||||
}, false);
|
||||
|
||||
// mouse wheel => zooming
|
||||
@@ -294,45 +337,45 @@ GCODE.renderer = (function(){
|
||||
ctx.beginPath();
|
||||
ctx.strokeStyle = renderOptions["colorGrid"];
|
||||
ctx.fillStyle = "#ffffff";
|
||||
ctx.lineWidth = 2;
|
||||
ctx.lineWidth = 2 * lineWidthFactor;
|
||||
|
||||
// outline
|
||||
ctx.rect(minX * zoomFactor, -1 * minY * zoomFactor, width * zoomFactor, -1 * height * zoomFactor);
|
||||
ctx.rect(minX, minY, width, height);
|
||||
|
||||
// origin
|
||||
ctx.moveTo(minX * zoomFactor, 0);
|
||||
ctx.lineTo(maxX * zoomFactor, 0);
|
||||
ctx.moveTo(0, -1 * minY * zoomFactor);
|
||||
ctx.lineTo(0, -1 * maxY * zoomFactor);
|
||||
ctx.moveTo(minX, 0);
|
||||
ctx.lineTo(maxX, 0);
|
||||
ctx.moveTo(0, minY);
|
||||
ctx.lineTo(0, maxY);
|
||||
|
||||
// draw
|
||||
ctx.fill();
|
||||
ctx.stroke();
|
||||
|
||||
ctx.strokeStyle = renderOptions["colorGrid"];
|
||||
ctx.lineWidth = 1;
|
||||
ctx.lineWidth = lineWidthFactor;
|
||||
|
||||
//~~ grid starting from origin
|
||||
ctx.beginPath();
|
||||
for (x = 0; x <= maxX; x += gridStep) {
|
||||
ctx.moveTo(x * zoomFactor, -1 * minY * zoomFactor);
|
||||
ctx.lineTo(x * zoomFactor, -1 * maxY * zoomFactor);
|
||||
ctx.moveTo(x, minY);
|
||||
ctx.lineTo(x, maxY);
|
||||
|
||||
if (renderOptions["bed"]["centeredOrigin"]) {
|
||||
ctx.moveTo(-1 * x * zoomFactor, -1 * minY * zoomFactor);
|
||||
ctx.lineTo(-1 * x * zoomFactor, -1 * maxY * zoomFactor);
|
||||
ctx.moveTo(-1 * x, minY);
|
||||
ctx.lineTo(-1 * x, maxY);
|
||||
}
|
||||
}
|
||||
ctx.stroke();
|
||||
|
||||
ctx.beginPath();
|
||||
for (y = 0; y <= maxY; y += gridStep) {
|
||||
ctx.moveTo(minX * zoomFactor, -1 * y * zoomFactor);
|
||||
ctx.lineTo(maxX * zoomFactor, -1 * y * zoomFactor);
|
||||
ctx.moveTo(minX, y);
|
||||
ctx.lineTo(maxX, y);
|
||||
|
||||
if (renderOptions["bed"]["centeredOrigin"]) {
|
||||
ctx.moveTo(minX * zoomFactor, y * zoomFactor);
|
||||
ctx.lineTo(maxX * zoomFactor, y * zoomFactor);
|
||||
ctx.moveTo(minX, -1 * y);
|
||||
ctx.lineTo(maxX, -1 * y);
|
||||
}
|
||||
}
|
||||
ctx.stroke();
|
||||
@@ -343,44 +386,45 @@ GCODE.renderer = (function(){
|
||||
|
||||
ctx.strokeStyle = renderOptions["colorGrid"];
|
||||
ctx.fillStyle = "#ffffff";
|
||||
ctx.lineWidth = 2;
|
||||
ctx.lineWidth = 2 * lineWidthFactor;
|
||||
|
||||
//~~ bed outline & origin
|
||||
ctx.beginPath();
|
||||
|
||||
// outline
|
||||
ctx.arc(0, 0, renderOptions["bed"]["r"] * zoomFactor, 0, Math.PI * 2, true);
|
||||
var r = renderOptions["bed"]["r"];
|
||||
ctx.arc(0, 0, r, 0, Math.PI * 2, true);
|
||||
|
||||
// origin
|
||||
ctx.moveTo(-1 * renderOptions["bed"]["r"] * zoomFactor, 0);
|
||||
ctx.lineTo(renderOptions["bed"]["r"] * zoomFactor, 0);
|
||||
ctx.moveTo(0, -1 * renderOptions["bed"]["r"] * zoomFactor);
|
||||
ctx.lineTo(0, renderOptions["bed"]["r"] * zoomFactor);
|
||||
ctx.moveTo(-1 * r, 0);
|
||||
ctx.lineTo(r, 0);
|
||||
ctx.moveTo(0, r);
|
||||
ctx.lineTo(0, -1 * r);
|
||||
|
||||
// draw
|
||||
ctx.fill();
|
||||
ctx.stroke();
|
||||
|
||||
ctx.strokeStyle = renderOptions["colorGrid"];
|
||||
ctx.lineWidth = 1;
|
||||
ctx.lineWidth = lineWidthFactor;
|
||||
|
||||
//~~ grid starting from origin
|
||||
ctx.beginPath();
|
||||
for (i = 0; i <= renderOptions["bed"]["r"]; i += gridStep) {
|
||||
for (i = 0; i <= r; i += gridStep) {
|
||||
var x = i;
|
||||
var y = Math.sqrt(Math.pow(renderOptions["bed"]["r"], 2) - Math.pow(x, 2));
|
||||
var y = Math.sqrt(r*r - x*x);
|
||||
|
||||
ctx.moveTo(x * zoomFactor, y * zoomFactor);
|
||||
ctx.lineTo(x * zoomFactor, -1 * y * zoomFactor);
|
||||
ctx.moveTo(x, -1 * y);
|
||||
ctx.lineTo(x, y);
|
||||
|
||||
ctx.moveTo(y * zoomFactor, x * zoomFactor);
|
||||
ctx.lineTo(-1 * y * zoomFactor, x * zoomFactor);
|
||||
ctx.moveTo(y, -1 * x);
|
||||
ctx.lineTo(-1 * y, -1 * x);
|
||||
|
||||
ctx.moveTo(-1 * x * zoomFactor, y * zoomFactor);
|
||||
ctx.lineTo(-1 * x * zoomFactor, -1 * y * zoomFactor);
|
||||
ctx.moveTo(-1 * x, -1 * y);
|
||||
ctx.lineTo(-1 * x, y);
|
||||
|
||||
ctx.moveTo(y * zoomFactor, -1 * x * zoomFactor);
|
||||
ctx.lineTo(-1 * y * zoomFactor, -1 * x * zoomFactor);
|
||||
ctx.moveTo(y, x);
|
||||
ctx.lineTo(-1 * y, x);
|
||||
}
|
||||
ctx.stroke();
|
||||
};
|
||||
@@ -391,31 +435,31 @@ GCODE.renderer = (function(){
|
||||
var minX, minY, width, height;
|
||||
|
||||
if (renderOptions["showFullSize"]) {
|
||||
minX = modelInfo.min.x * zoomFactor;
|
||||
minY = modelInfo.min.y * zoomFactor;
|
||||
width = modelInfo.modelSize.x * zoomFactor;
|
||||
height = modelInfo.modelSize.y * zoomFactor;
|
||||
minX = modelInfo.min.x;
|
||||
minY = modelInfo.min.y;
|
||||
width = modelInfo.modelSize.x;
|
||||
height = modelInfo.modelSize.y;
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.strokeStyle = "#0000ff";
|
||||
ctx.setLineDash([2, 5]);
|
||||
|
||||
ctx.rect(minX, minY * -1, width, height * -1);
|
||||
ctx.rect(minX, minY, width, height);
|
||||
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
if (renderOptions["showBoundingBox"]) {
|
||||
minX = modelInfo.boundingBox.minX * zoomFactor;
|
||||
minY = modelInfo.boundingBox.minY * zoomFactor;
|
||||
width = modelInfo.boundingBox.maxX * zoomFactor - minX;
|
||||
height = modelInfo.boundingBox.maxY * zoomFactor - minY;
|
||||
minX = modelInfo.boundingBox.minX;
|
||||
minY = modelInfo.boundingBox.minY;
|
||||
width = modelInfo.boundingBox.maxX - minX;
|
||||
height = modelInfo.boundingBox.maxY - minY;
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.strokeStyle = "#ff0000";
|
||||
ctx.setLineDash([2, 5]);
|
||||
|
||||
ctx.rect(minX, minY * -1, width, height * -1);
|
||||
ctx.rect(minX, minY, width, height);
|
||||
|
||||
ctx.stroke();
|
||||
}
|
||||
@@ -439,29 +483,35 @@ GCODE.renderer = (function(){
|
||||
*/
|
||||
|
||||
var ax, bx, cx, ay, by, cy;
|
||||
var h = Math.sqrt(0.75 * length * length);
|
||||
var h = Math.sqrt(0.75 * length * length) / 2;
|
||||
|
||||
ax = centerX - length / 2;
|
||||
bx = centerX + length / 2;
|
||||
bx = ax + length;
|
||||
cx = centerX;
|
||||
|
||||
if (up) {
|
||||
ay = centerY + h / 2;
|
||||
by = centerY + h / 2;
|
||||
cy = centerY - h / 2;
|
||||
ay = centerY - h;
|
||||
by = centerY - h;
|
||||
cy = centerY + h;
|
||||
} else {
|
||||
ay = centerY - h / 2;
|
||||
by = centerY - h / 2;
|
||||
cy = centerY + h / 2;
|
||||
ay = centerY + h;
|
||||
by = centerY + h;
|
||||
cy = centerY - h;
|
||||
}
|
||||
|
||||
var origLineJoin = ctx.lineJoin;
|
||||
ctx.lineJoin = "miter";
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(ax, ay);
|
||||
ctx.lineTo(bx, by);
|
||||
ctx.moveTo(bx, by);
|
||||
ctx.lineTo(cx, cy);
|
||||
ctx.lineTo(ax, ay);
|
||||
ctx.stroke();
|
||||
ctx.fill();
|
||||
|
||||
ctx.lineJoin = origLineJoin;
|
||||
};
|
||||
|
||||
var drawLayer = function(layerNum, fromProgress, toProgress, isNotCurrentLayer){
|
||||
@@ -472,11 +522,6 @@ GCODE.renderer = (function(){
|
||||
//~~ store current layer values
|
||||
|
||||
isNotCurrentLayer = isNotCurrentLayer !== undefined ? isNotCurrentLayer : false;
|
||||
if (!isNotCurrentLayer) {
|
||||
// not not current layer == current layer => store layer number and from/to progress
|
||||
layerNumStore = layerNum;
|
||||
progressStore = {from: fromProgress, to: toProgress};
|
||||
}
|
||||
|
||||
if (!model || !model[layerNum]) return;
|
||||
|
||||
@@ -487,19 +532,28 @@ GCODE.renderer = (function(){
|
||||
|
||||
if (cmds[0].prevX !== undefined && cmds[0].prevY !== undefined) {
|
||||
// command contains prevX/prevY values, use those
|
||||
prevX = cmds[0].prevX * zoomFactor;
|
||||
prevY = -1 * cmds[0].prevY * zoomFactor;
|
||||
prevX = cmds[0].prevX;
|
||||
prevY = cmds[0].prevY;
|
||||
} else if (fromProgress > 0) {
|
||||
// previous command in same layer exists, use x/y as prevX/prevY
|
||||
prevX = cmds[fromProgress - 1].x * zoomFactor;
|
||||
prevY = -cmds[fromProgress - 1].y * zoomFactor;
|
||||
prevX = cmds[fromProgress - 1].x;
|
||||
prevY = cmds[fromProgress - 1].y;
|
||||
} else if (model[layerNum - 1]) {
|
||||
// previous layer exists, use last x/y as prevX/prevY
|
||||
prevX = undefined;
|
||||
prevY = undefined;
|
||||
for (i = model[layerNum-1].length-1; i >= 0; i--) {
|
||||
if (prevX === undefined && model[layerNum - 1][i].x !== undefined) prevX = model[layerNum - 1][i].x * zoomFactor;
|
||||
if (prevY === undefined && model[layerNum - 1][i].y !== undefined) prevY =- model[layerNum - 1][i].y * zoomFactor;
|
||||
var prevModelLayer = model[layerNum-1];
|
||||
for (i = prevModelLayer.length-1; i >= 0; i--) {
|
||||
if (prevX === undefined && prevModelLayer[i].x !== undefined) {
|
||||
prevX = prevModelLayer[i].x;
|
||||
if (prevY !== undefined)
|
||||
break;
|
||||
}
|
||||
if (prevY === undefined && prevModelLayer[i].y !== undefined) {
|
||||
prevY = prevModelLayer[i].y;
|
||||
if (prevX !== undefined)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -510,106 +564,160 @@ GCODE.renderer = (function(){
|
||||
|
||||
//~~ render this layer's commands
|
||||
|
||||
var sizeRetractSpot = renderOptions["sizeRetractSpot"] * lineWidthFactor * 2;
|
||||
|
||||
// alpha value (100% if current layer is being rendered, 30% otherwise)
|
||||
var alpha = (renderOptions['showNextLayer'] || renderOptions['showPreviousLayer']) && isNotCurrentLayer ? 0.3 : 1.0;
|
||||
|
||||
var colorLine = {};
|
||||
var colorMove = {};
|
||||
var colorRetract = {};
|
||||
var colorRestart = {};
|
||||
|
||||
function getColorLineForTool(tool) {
|
||||
var rv = colorLine[tool];
|
||||
if (rv === undefined) {
|
||||
var lineColor = renderOptions["colorLine"][tool];
|
||||
if (lineColor === undefined) lineColor = renderOptions["colorLine"][0];
|
||||
var shade = tool * 0.15;
|
||||
rv = colorLine[tool] = pusher.color(lineColor).shade(shade).alpha(alpha).html();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
function getColorMoveForTool(tool) {
|
||||
var rv = colorMove[tool];
|
||||
if (rv === undefined) {
|
||||
var shade = tool * 0.15;
|
||||
rv = colorMove[tool] = pusher.color(renderOptions["colorMove"]).shade(shade).alpha(alpha).html();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
function getColorRetractForTool(tool) {
|
||||
var rv = colorRetract[tool];
|
||||
if (rv === undefined) {
|
||||
var shade = tool * 0.15;
|
||||
rv = colorRetract[tool] = pusher.color(renderOptions["colorRetract"]).shade(shade).alpha(alpha).html();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
function getColorRestartForTool(tool) {
|
||||
var rv = colorRestart[tool];
|
||||
if (rv === undefined) {
|
||||
var shade = tool * 0.15;
|
||||
rv = colorRestart[tool] = pusher.color(renderOptions["colorRestart"]).shade(shade).alpha(alpha).html();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
var prevPathType = "fill";
|
||||
function strokePathIfNeeded(newPathType, strokeStyle) {
|
||||
if ((newPathType != prevPathType) || (newPathType == "fill")) {
|
||||
if (prevPathType != "fill") {
|
||||
ctx.stroke();
|
||||
}
|
||||
prevPathType = newPathType;
|
||||
|
||||
ctx.beginPath();
|
||||
if (newPathType != "fill") {
|
||||
ctx.strokeStyle = strokeStyle;
|
||||
ctx.moveTo(prevX, prevY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ctx.lineJoin = "round";
|
||||
|
||||
for (i = fromProgress; i <= toProgress; i++) {
|
||||
ctx.lineWidth = 1;
|
||||
|
||||
if (typeof(cmds[i]) === 'undefined') continue;
|
||||
var cmd = cmds[i];
|
||||
|
||||
if (typeof(cmds[i].prevX) !== 'undefined' && typeof(cmds[i].prevY) !== 'undefined') {
|
||||
if (cmd.prevX !== undefined && cmd.prevY !== undefined) {
|
||||
// override new (prevX, prevY)
|
||||
prevX = cmds[i].prevX * zoomFactor;
|
||||
prevY = -1 * cmds[i].prevY * zoomFactor;
|
||||
prevX = cmd.prevX;
|
||||
prevY = cmd.prevY;
|
||||
}
|
||||
|
||||
// new x
|
||||
if (typeof(cmds[i].x) === 'undefined' || isNaN(cmds[i].x)) {
|
||||
x = prevX / zoomFactor;
|
||||
if (cmd.x === undefined || isNaN(cmd.x)) {
|
||||
x = prevX;
|
||||
} else {
|
||||
x = cmds[i].x;
|
||||
x = cmd.x;
|
||||
}
|
||||
|
||||
// new y
|
||||
if (typeof(cmds[i].y) === 'undefined' || isNaN(cmds[i].y)) {
|
||||
y = prevY / zoomFactor;
|
||||
if (cmd.y === undefined || isNaN(cmd.y)) {
|
||||
y = prevY;
|
||||
} else {
|
||||
y = -cmds[i].y;
|
||||
y = cmd.y;
|
||||
}
|
||||
|
||||
// current tool
|
||||
var tool = cmds[i].tool;
|
||||
if (tool === undefined) tool = 0;
|
||||
var tool = cmd.tool || 0;
|
||||
|
||||
// line color based on tool
|
||||
var lineColor = renderOptions["colorLine"][tool];
|
||||
if (lineColor === undefined) lineColor = renderOptions["colorLine"][0];
|
||||
|
||||
// alpha value (100% if current layer is being rendered, 30% otherwise)
|
||||
var alpha = (renderOptions['showNextLayer'] || renderOptions['showPreviousLayer']) && isNotCurrentLayer ? 0.3 : 1.0;
|
||||
var shade = tool * 0.15;
|
||||
|
||||
if (!cmds[i].extrude && !cmds[i].noMove) {
|
||||
if (!cmd.extrude && !cmd.noMove) {
|
||||
// neither extrusion nor move
|
||||
if (cmds[i].retract === -1) {
|
||||
if (cmd.retract == -1) {
|
||||
// retract => draw dot if configured to do so
|
||||
if (renderOptions["showRetracts"]) {
|
||||
ctx.strokeStyle = pusher.color(renderOptions["colorRetract"]).shade(shade).alpha(alpha).html();
|
||||
ctx.fillStyle = pusher.color(renderOptions["colorRetract"]).shade(shade).alpha(alpha).html();
|
||||
drawTriangle(prevX, prevY, renderOptions["sizeRetractSpot"] * 2, true);
|
||||
strokePathIfNeeded("fill");
|
||||
ctx.fillStyle = getColorRetractForTool(tool);
|
||||
ctx.strokeStyle = ctx.fillStyle;
|
||||
drawTriangle(prevX, prevY, sizeRetractSpot, true);
|
||||
}
|
||||
}
|
||||
|
||||
strokePathIfNeeded("move", getColorMoveForTool(tool));
|
||||
if(renderOptions["showMoves"]){
|
||||
// move => draw line from (prevX, prevY) to (x, y) in move color
|
||||
ctx.strokeStyle = pusher.color(renderOptions["colorMove"]).shade(shade).alpha(alpha).html();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(prevX, prevY);
|
||||
ctx.lineTo(x*zoomFactor,y*zoomFactor);
|
||||
ctx.stroke();
|
||||
ctx.lineWidth = lineWidthFactor;
|
||||
ctx.lineTo(x,y);
|
||||
}
|
||||
} else if(cmds[i].extrude) {
|
||||
if (cmds[i].retract === 0) {
|
||||
} else if(cmd.extrude) {
|
||||
if (cmd.retract == 0) {
|
||||
// no retraction => real extrusion move, use tool color to draw line
|
||||
ctx.strokeStyle = pusher.color(renderOptions["colorLine"][tool]).shade(shade).alpha(alpha).html();
|
||||
ctx.lineWidth = renderOptions['extrusionWidth'];
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(prevX, prevY);
|
||||
if (cmds[i].direction !== undefined && cmds[i].direction !== 0){
|
||||
var cmd = cmds[i];
|
||||
var di = cmd.i*zoomFactor;
|
||||
var dj = -1*cmd.j*zoomFactor; // Y-coordinate is inverted
|
||||
strokePathIfNeeded("extrude", getColorLineForTool(tool));
|
||||
ctx.lineWidth = renderOptions['extrusionWidth'] * lineWidthFactor;
|
||||
if (cmd.direction !== undefined && cmd.direction != 0){
|
||||
var di = cmd.i;
|
||||
var dj = cmd.j;
|
||||
var centerX = prevX+di;
|
||||
var centerY = prevY+dj;
|
||||
var startAngle = Math.atan2(prevY-centerY, prevX - centerX);
|
||||
var endAngle = Math.atan2(y*zoomFactor-centerY, x*zoomFactor - centerX);
|
||||
var endAngle = Math.atan2(y - centerY, x - centerX);
|
||||
var radius=Math.sqrt(di*di+dj*dj);
|
||||
ctx.arc(centerX,centerY,radius,startAngle,endAngle,cmd.direction<0); // Y-coordinate is inverted so direction is also inverted
|
||||
ctx.arc(centerX,centerY,radius,startAngle,endAngle,cmd.direction<0); // Y-axis is inverted so direction is also inverted
|
||||
} else {
|
||||
ctx.lineTo(x*zoomFactor,y*zoomFactor);
|
||||
ctx.lineTo(x,y);
|
||||
}
|
||||
ctx.stroke();
|
||||
} else {
|
||||
// we were previously retracting, now we are restarting => draw dot if configured to do so
|
||||
if (renderOptions["showRetracts"]) {
|
||||
ctx.strokeStyle = pusher.color(renderOptions["colorRestart"]).shade(shade).alpha(alpha).html();
|
||||
ctx.fillStyle = pusher.color(renderOptions["colorRestart"]).shade(shade).alpha(alpha).html();
|
||||
drawTriangle(prevX, prevY, renderOptions["sizeRetractSpot"] * 2, false);
|
||||
strokePathIfNeeded("fill");
|
||||
ctx.fillStyle = getColorRestartForTool(tool);
|
||||
ctx.strokeStyle = ctx.fillStyle;
|
||||
drawTriangle(prevX, prevY, sizeRetractSpot, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set new (prevX, prevY)
|
||||
prevX = x * zoomFactor;
|
||||
prevY = y * zoomFactor;
|
||||
prevX = x;
|
||||
prevY = y;
|
||||
}
|
||||
|
||||
if (prevPathType != "fill") {
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
ctx.stroke();
|
||||
|
||||
if (renderOptions["showHead"]) {
|
||||
ctx.strokeStyle = pusher.color(renderOptions["colorHead"]).shade(shade).alpha(alpha).html();
|
||||
var sizeHeadSpot = renderOptions["sizeHeadSpot"] * lineWidthFactor + lineWidthFactor / 2;
|
||||
var shade = tool * 0.15;
|
||||
ctx.fillStyle = pusher.color(renderOptions["colorHead"]).shade(shade).alpha(alpha).html();
|
||||
ctx.beginPath();
|
||||
ctx.arc(prevX, prevY, renderOptions["sizeHeadSpot"], 0, Math.PI*2, true);
|
||||
ctx.stroke();
|
||||
ctx.arc(prevX, prevY, sizeHeadSpot, 0, Math.PI*2, true);
|
||||
ctx.fill();
|
||||
}
|
||||
};
|
||||
@@ -622,8 +730,8 @@ GCODE.renderer = (function(){
|
||||
if (renderOptions["centerViewport"] || renderOptions["zoomInOnModel"]) {
|
||||
canvasCenter = ctx.transformedPoint(canvas.width / 2, canvas.height / 2);
|
||||
if (modelInfo) {
|
||||
offsetModelX = canvasCenter.x - (modelInfo.boundingBox.minX + modelInfo.boundingBox.maxX) * zoomFactor / 2;
|
||||
offsetModelY = canvasCenter.y + (modelInfo.boundingBox.minY + modelInfo.boundingBox.maxY) * zoomFactor / 2;
|
||||
offsetModelX = canvasCenter.x - (modelInfo.boundingBox.minX + modelInfo.boundingBox.maxX) / 2;
|
||||
offsetModelY = canvasCenter.y - (modelInfo.boundingBox.minY + modelInfo.boundingBox.maxY) / 2;
|
||||
} else {
|
||||
offsetModelX = 0;
|
||||
offsetModelY = 0;
|
||||
@@ -631,10 +739,10 @@ GCODE.renderer = (function(){
|
||||
offsetBedX = 0;
|
||||
offsetBedY = 0;
|
||||
} else if (modelInfo && renderOptions["moveModel"]) {
|
||||
offsetModelX = (renderOptions["bed"]["x"] / 2 - (modelInfo.boundingBox.minX + modelInfo.boundingBox.maxX) / 2) * zoomFactor;
|
||||
offsetModelY = -1 * (renderOptions["bed"]["y"] / 2 - (modelInfo.boundingBox.minY + modelInfo.boundingBox.maxY) / 2) * zoomFactor;
|
||||
offsetBedX = -1 * (renderOptions["bed"]["x"] / 2 - (modelInfo.boundingBox.minX + modelInfo.boundingBox.maxX) / 2) * zoomFactor;
|
||||
offsetBedY = (renderOptions["bed"]["y"] / 2 - (modelInfo.boundingBox.minY + modelInfo.boundingBox.maxY) / 2) * zoomFactor;
|
||||
offsetModelX = (renderOptions["bed"]["x"] / 2 - (modelInfo.boundingBox.minX + modelInfo.boundingBox.maxX) / 2);
|
||||
offsetModelY = (renderOptions["bed"]["y"] / 2 - (modelInfo.boundingBox.minY + modelInfo.boundingBox.maxY) / 2);
|
||||
offsetBedX = -1 * (renderOptions["bed"]["x"] / 2 - (modelInfo.boundingBox.minX + modelInfo.boundingBox.maxX) / 2);
|
||||
offsetBedY = -1 * (renderOptions["bed"]["y"] / 2 - (modelInfo.boundingBox.minY + modelInfo.boundingBox.maxY) / 2);
|
||||
} else if (renderOptions["bed"]["circular"] || renderOptions["bed"]["centeredOrigin"]) {
|
||||
canvasCenter = ctx.transformedPoint(canvas.width / 2, canvas.height / 2);
|
||||
offsetModelX = canvasCenter.x;
|
||||
@@ -671,10 +779,9 @@ GCODE.renderer = (function(){
|
||||
var length = modelInfo.boundingBox.maxY - modelInfo.boundingBox.minY;
|
||||
|
||||
var scaleF = width > length ? (canvas.width - 10) / width : (canvas.height - 10) / length;
|
||||
scaleF /= zoomFactor;
|
||||
if (transform.a && transform.d) {
|
||||
scaleX = scaleF / transform.a * (renderOptions["invertAxes"]["x"] ? -1 : 1);
|
||||
scaleY = scaleF / transform.d * (renderOptions["invertAxes"]["y"] ? -1 : 1);
|
||||
scaleY = scaleF / transform.d * (renderOptions["invertAxes"]["y"] ? 1 : -1);
|
||||
ctx.translate(pt.x,pt.y);
|
||||
ctx.scale(scaleX, scaleY);
|
||||
ctx.translate(-pt.x, -pt.y);
|
||||
@@ -721,22 +828,30 @@ GCODE.renderer = (function(){
|
||||
if(renderOptions["bed"]["circular"]) {
|
||||
bedWidth = bedHeight = renderOptions["bed"]["r"] * 2;
|
||||
}
|
||||
zoomFactor = Math.min((canvas.width - 10) / bedWidth, (canvas.height - 10) / bedHeight);
|
||||
|
||||
// Ratio of bed to canvas viewport
|
||||
var viewportRatio = Math.min((canvas.width - 10) / bedWidth, (canvas.height - 10) / bedHeight);
|
||||
|
||||
// Apply initial translation to center the bed in the viewport
|
||||
var translationX, translationY;
|
||||
if (renderOptions["bed"]["circular"]) {
|
||||
translationX = canvas.width / 2;
|
||||
translationY = canvas.height / 2;
|
||||
} else {
|
||||
translationX = (canvas.width - bedWidth * zoomFactor) / 2;
|
||||
translationY = bedHeight * zoomFactor + (canvas.height - bedHeight * zoomFactor) / 2;
|
||||
translationX = (canvas.width - bedWidth * viewportRatio) / 2;
|
||||
translationY = bedHeight * viewportRatio + (canvas.height - bedHeight * viewportRatio) / 2;
|
||||
}
|
||||
ctx.translate(translationX, translationY);
|
||||
ctx.translate(translationX, -translationY);
|
||||
|
||||
ctx.scale(viewportRatio, viewportRatio);
|
||||
|
||||
offsetModelX = 0;
|
||||
offsetModelY = 0;
|
||||
offsetBedX = 0;
|
||||
offsetBedY = 0;
|
||||
|
||||
// Scaling to apply to move lines and extrusion/retraction markers
|
||||
lineWidthFactor = 1 / viewportRatio;
|
||||
},
|
||||
setOption: function(options){
|
||||
var mustRefresh = false;
|
||||
@@ -748,7 +863,7 @@ GCODE.renderer = (function(){
|
||||
|
||||
dirty = true;
|
||||
renderOptions[opt] = options[opt];
|
||||
if ($.inArray(opt, ["moveModel", "centerViewport", "zoomInOnModel", "bed", "invertAxes"]) > -1) {
|
||||
if ($.inArray(opt, ["moveModel", "centerViewport", "zoomInOnModel", "bed", "invertAxes", "onViewportChange"]) > -1) {
|
||||
mustRefresh = true;
|
||||
}
|
||||
}
|
||||
@@ -770,25 +885,12 @@ GCODE.renderer = (function(){
|
||||
},
|
||||
render: function(layerNum, fromProgress, toProgress){
|
||||
if (!initialized) this.init();
|
||||
|
||||
layerNumStore = layerNum;
|
||||
progressStore.from = fromProgress;
|
||||
progressStore.to = toProgress;
|
||||
|
||||
var p1 = ctx.transformedPoint(0, 0);
|
||||
var p2 = ctx.transformedPoint(canvas.width, canvas.height);
|
||||
ctx.clearRect(p1.x, p1.y, p2.x - p1.x, p2.y - p1.y);
|
||||
drawGrid();
|
||||
drawBoundingBox();
|
||||
if (model && model.length) {
|
||||
if (layerNum < model.length) {
|
||||
if (renderOptions['showNextLayer'] && layerNum < model.length - 1) {
|
||||
drawLayer(layerNum + 1, 0, this.getLayerNumSegments(layerNum + 1), true);
|
||||
}
|
||||
if (renderOptions['showPreviousLayer'] && layerNum > 0) {
|
||||
drawLayer(layerNum - 1, 0, this.getLayerNumSegments(layerNum - 1), true);
|
||||
}
|
||||
drawLayer(layerNum, fromProgress, toProgress);
|
||||
} else {
|
||||
console.log("Got request to render non-existent layer");
|
||||
}
|
||||
}
|
||||
reRender();
|
||||
},
|
||||
getModelNumLayers: function(){
|
||||
return model ? model.length : 1;
|
||||
@@ -838,7 +940,7 @@ GCODE.renderer = (function(){
|
||||
this.render(layerNum, 0, toProgress);
|
||||
},
|
||||
refresh: function(layerNum) {
|
||||
if (!layerNum) layerNum = layerNumStore;
|
||||
if (layerNum === undefined) layerNum = layerNumStore;
|
||||
this.doRender(model, layerNum);
|
||||
},
|
||||
getZ: function(layerNum){
|
||||
|
||||
@@ -22,6 +22,7 @@ import octoprint.util as util
|
||||
|
||||
from octoprint.settings import settings
|
||||
from octoprint.events import eventManager, Events
|
||||
from octoprint.plugin import plugin_manager
|
||||
from octoprint.util import monotonic_time
|
||||
from octoprint.util.commandline import CommandlineCaller
|
||||
|
||||
@@ -67,6 +68,30 @@ _cleanup_lock = threading.RLock()
|
||||
# lock for timelapse job
|
||||
_job_lock = threading.RLock()
|
||||
|
||||
# cached valid timelapse extensions
|
||||
_extensions = None
|
||||
|
||||
def valid_timelapse(path):
|
||||
global _extensions
|
||||
|
||||
if _extensions is None:
|
||||
# create list of extensions
|
||||
extensions = ["mpg", "mpeg", "mp4", "m4v", "mkv"]
|
||||
|
||||
hooks = plugin_manager().get_hooks("octoprint.timelapse.extensions")
|
||||
for name, hook in hooks.items():
|
||||
try:
|
||||
result = hook()
|
||||
if result is None or not isinstance(result, list):
|
||||
continue
|
||||
extensions += result
|
||||
except:
|
||||
logging.getLogger(__name__).exception("Exception while retrieving additional timelapse extensions from hook {name}".format(name=name))
|
||||
|
||||
_extensions = list(set(extensions))
|
||||
|
||||
return util.is_allowed_file(path, _extensions)
|
||||
|
||||
|
||||
def _extract_prefix(filename):
|
||||
"""
|
||||
@@ -93,7 +118,7 @@ def get_finished_timelapses():
|
||||
files = []
|
||||
basedir = settings().getBaseFolder("timelapse")
|
||||
for entry in scandir(basedir):
|
||||
if not fnmatch.fnmatch(entry.name, "*.m*"):
|
||||
if util.is_hidden_path(entry.path) or not valid_timelapse(entry.path):
|
||||
continue
|
||||
files.append({
|
||||
"name": entry.name,
|
||||
|
||||
+33
-22
@@ -781,6 +781,9 @@ class MachineCom(object):
|
||||
return self._job_on_hold.counter > 0
|
||||
|
||||
def set_job_on_hold(self, value, blocking=True):
|
||||
trigger = False
|
||||
|
||||
# don't run any locking code beyond this...
|
||||
if not self._job_on_hold.acquire(blocking=blocking):
|
||||
return False
|
||||
|
||||
@@ -790,10 +793,14 @@ class MachineCom(object):
|
||||
else:
|
||||
self._job_on_hold.clear()
|
||||
if self._job_on_hold.counter == 0:
|
||||
self._continue_sending()
|
||||
trigger = True
|
||||
finally:
|
||||
self._job_on_hold.release()
|
||||
|
||||
# locking code is now safe to run again
|
||||
if trigger:
|
||||
self._continue_sending()
|
||||
|
||||
return True
|
||||
|
||||
def close(self, is_error=False, wait=True, timeout=10.0, *args, **kwargs):
|
||||
@@ -1491,11 +1498,13 @@ class MachineCom(object):
|
||||
self.sayHello()
|
||||
|
||||
while self._monitoring_active:
|
||||
now = time.time()
|
||||
try:
|
||||
line = self._readline()
|
||||
if line is None:
|
||||
break
|
||||
|
||||
now = time.time()
|
||||
|
||||
if line.strip() is not "":
|
||||
self._consecutive_timeouts = 0
|
||||
self._timeout = get_new_timeout("communicationBusy" if self._busy_protocol_detected else "communication", self._timeout_intervals)
|
||||
@@ -1610,7 +1619,7 @@ class MachineCom(object):
|
||||
handled = False
|
||||
|
||||
# process oks
|
||||
if line.startswith("ok") or (self.isPrinting() and not self.job_on_hold and supportWait and line == "wait"):
|
||||
if line.startswith("ok") or (self.isPrinting() and supportWait and line == "wait"):
|
||||
# ok only considered handled if it's alone on the line, might be
|
||||
# a response to an M105 or an M114
|
||||
self._handle_ok()
|
||||
@@ -1624,11 +1633,11 @@ class MachineCom(object):
|
||||
handled = True
|
||||
|
||||
# process timeouts
|
||||
elif ((line == "" and now > self._timeout) or (self.isPrinting()
|
||||
and not self.isSdPrinting()
|
||||
and not self.job_on_hold
|
||||
and not self._long_running_command
|
||||
and not self._heating and now > self._ok_timeout)) \
|
||||
elif ((line == "" and now >= self._timeout) or (self.isPrinting()
|
||||
and not self.isSdPrinting()
|
||||
and (not self.job_on_hold or self._resendActive)
|
||||
and not self._long_running_command
|
||||
and not self._heating and now >= self._ok_timeout)) \
|
||||
and (not self._blockWhileDwelling or not self._dwelling_until or now > self._dwelling_until):
|
||||
# We have two timeout variants:
|
||||
#
|
||||
@@ -2043,21 +2052,16 @@ class MachineCom(object):
|
||||
if not self._state in self.OPERATIONAL_STATES:
|
||||
return
|
||||
|
||||
# process queues ongoing resend requests and queues if we are operational
|
||||
if self._resendDelta is not None and self._resendNextCommand():
|
||||
# we processed a resend request and are done here
|
||||
return
|
||||
|
||||
with self._sendingLock: # prevent concurrency due to resend_ok_timers
|
||||
if self._resendDelta is not None:
|
||||
self._resendNextCommand()
|
||||
else:
|
||||
self._resendActive = False
|
||||
self._continue_sending()
|
||||
|
||||
return
|
||||
# continue with our queues and the job
|
||||
self._resendActive = False
|
||||
self._continue_sending()
|
||||
|
||||
def _handle_timeout(self):
|
||||
if self._state not in (self.STATE_PRINTING,
|
||||
self.STATE_PAUSED,
|
||||
self.STATE_OPERATIONAL):
|
||||
if self._state not in self.OPERATIONAL_STATES:
|
||||
return
|
||||
|
||||
general_message = "Configure long running commands or increase communication timeout if that happens regularly on specific commands or long moves."
|
||||
@@ -2065,7 +2069,7 @@ class MachineCom(object):
|
||||
# figure out which consecutive timeout maximum we have to use
|
||||
if self._long_running_command:
|
||||
consecutive_max = self._consecutive_timeout_maximums.get("long", 0)
|
||||
elif self._state in (self.STATE_PRINTING,):
|
||||
elif self._state in self.PRINTING_STATES:
|
||||
consecutive_max = self._consecutive_timeout_maximums.get("printing", 0)
|
||||
else:
|
||||
consecutive_max = self._consecutive_timeout_maximums.get("idle", 0)
|
||||
@@ -2101,7 +2105,7 @@ class MachineCom(object):
|
||||
# long running command active, ignore timeout
|
||||
self._logger.debug("Ran into a communication timeout, but a command known to be a long runner is currently active")
|
||||
|
||||
elif self._state in (self.STATE_PRINTING, self.STATE_PAUSED):
|
||||
elif self._state in self.PRINTING_STATES + (self.STATE_PAUSED,):
|
||||
# printing, try to tickle the printer
|
||||
message = "Communication timeout while printing, trying to trigger response from printer."
|
||||
self._logger.info(message)
|
||||
@@ -2756,6 +2760,11 @@ class MachineCom(object):
|
||||
self._resendDelta = 0
|
||||
self._resendDelta += 1
|
||||
|
||||
elif self._resendDelta is None:
|
||||
# we might enter this twice in quick succession if we get triggered by the
|
||||
# resend_ok_timer, so make sure that resendDelta is actually still set (see #2632)
|
||||
return False
|
||||
|
||||
cmd = self._lastLines[-self._resendDelta]
|
||||
lineNumber = self._currentLine - self._resendDelta
|
||||
|
||||
@@ -2763,6 +2772,8 @@ class MachineCom(object):
|
||||
|
||||
self._resendDelta -= 1
|
||||
if self._resendDelta <= 0:
|
||||
# reset everything BUT the resendActive flag - that will have to stay active until we receive
|
||||
# our next ok!
|
||||
self._resendDelta = None
|
||||
self._lastResendNumber = None
|
||||
self._currentResendCount = 0
|
||||
|
||||
@@ -78,7 +78,7 @@ class CommandlineCaller(object):
|
||||
self._logger.debug(u"Calling: {}".format(joined_command))
|
||||
self.on_log_call(joined_command)
|
||||
|
||||
kwargs.update(dict(async=True, stdout=sarge.Capture(), stderr=sarge.Capture()))
|
||||
kwargs.update(dict(async_=True, stdout=sarge.Capture(), stderr=sarge.Capture()))
|
||||
|
||||
p = sarge.run(command, **kwargs)
|
||||
while len(p.commands) == 0:
|
||||
|
||||
@@ -152,12 +152,12 @@ class MinMax3D(object):
|
||||
self.max = Vector3D(None, None, None)
|
||||
|
||||
def record(self, coordinate):
|
||||
for c in "xyz":
|
||||
current_min = getattr(self.min, c)
|
||||
current_max = getattr(self.max, c)
|
||||
value = getattr(coordinate, c)
|
||||
setattr(self.min, c, value if current_min is None or value < current_min else current_min)
|
||||
setattr(self.max, c, value if current_max is None or value > current_max else current_max)
|
||||
self.min.x = coordinate.x if not self.min.x else min(self.min.x, coordinate.x)
|
||||
self.min.y = coordinate.y if not self.min.y else min(self.min.y, coordinate.y)
|
||||
self.min.z = coordinate.z if not self.min.z else min(self.min.z, coordinate.z)
|
||||
self.max.x = coordinate.x if not self.max.x else max(self.max.x, coordinate.x)
|
||||
self.max.y = coordinate.y if not self.max.y else max(self.max.y, coordinate.y)
|
||||
self.max.z = coordinate.z if not self.max.z else max(self.max.z, coordinate.z)
|
||||
|
||||
@property
|
||||
def size(self):
|
||||
@@ -498,7 +498,6 @@ def getCodeInt(line, code):
|
||||
|
||||
|
||||
def getCodeFloat(line, code):
|
||||
import math
|
||||
n = line.find(code) + 1
|
||||
if n < 1:
|
||||
return None
|
||||
@@ -511,4 +510,3 @@ def getCodeFloat(line, code):
|
||||
return val if not (math.isnan(val) or math.isinf(val)) else None
|
||||
except:
|
||||
return None
|
||||
|
||||
@@ -5,6 +5,7 @@ __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agp
|
||||
__copyright__ = "Copyright (C) 2016 The OctoPrint Project - Released under terms of the AGPLv3 License"
|
||||
|
||||
import unittest
|
||||
import ddt
|
||||
|
||||
try:
|
||||
import unittest.mock as mock
|
||||
@@ -18,9 +19,11 @@ from collections import namedtuple, OrderedDict
|
||||
_stat = namedtuple("StatResult", "st_size, st_ctime, st_mtime")
|
||||
_entry = namedtuple("DirEntry", "name, path, is_file, is_dir, stat")
|
||||
|
||||
import octoprint.plugin
|
||||
import octoprint.settings
|
||||
import octoprint.timelapse
|
||||
|
||||
@ddt.ddt
|
||||
class TimelapseTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
@@ -31,10 +34,35 @@ class TimelapseTest(unittest.TestCase):
|
||||
self.settings = mock.create_autospec(octoprint.settings.Settings)
|
||||
self.settings_getter.return_value = self.settings
|
||||
|
||||
self.plugin_manager_patcher = mock.patch("octoprint.timelapse.plugin_manager")
|
||||
self.plugin_manager_getter = self.plugin_manager_patcher.start()
|
||||
|
||||
self.plugin_manager = mock.create_autospec(octoprint.plugin.PluginManager)
|
||||
self.plugin_manager_getter.return_value = self.plugin_manager
|
||||
|
||||
def extension_factory(*args, **kwargs):
|
||||
return ["gif"]
|
||||
hooks = dict(test=extension_factory)
|
||||
self.plugin_manager.get_hooks.return_value = hooks
|
||||
|
||||
self.now = time.time()
|
||||
|
||||
def cleanUp(self):
|
||||
self.settings_patcher.stop()
|
||||
self.plugin_manager_patcher.stop()
|
||||
|
||||
@ddt.data(
|
||||
("test.mpg", True),
|
||||
("test.dat", False),
|
||||
("test.gif", True)
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_valid_timelapse(self, input, expected):
|
||||
## test
|
||||
actual = octoprint.timelapse.valid_timelapse(input)
|
||||
|
||||
## verify
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
@mock.patch("os.remove")
|
||||
@mock.patch("octoprint.timelapse.scandir")
|
||||
|
||||
Reference in new issue
Block a user