Compare commits
6 commits
stable-1.2
...
mrbeam-dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
21e7a885b4 | ||
|
|
08d023be53 | ||
|
|
89d493a33b | ||
|
|
d89ec331da | ||
|
|
f54d932928 | ||
|
|
14f83133b7 |
|
|
@ -235,7 +235,7 @@ class SvgToGcodePlugin(octoprint.plugin.SlicerPlugin,
|
|||
|
||||
def get_assets(self):
|
||||
return dict(
|
||||
js=[ "js/convert.js", "js/working_area.js", "js/gcode_parser.js", "js/lib/snap.svg-min.js", "js/lib/photobooth_min.js", "js/matrix_oven.js", "js/render_fills.js", "js/drag_scale_rotate.js"],
|
||||
js=[ "js/convert.js", "js/working_area.js", "js/gcode_parser.js", "js/lib/snap.svg-min.js", "js/lib/photobooth_min.js", "js/matrix_oven.js", "js/render_fills.js", "js/drag_scale_rotate.js","js/extrude.js"],
|
||||
less=["less/svgtogcode.less"],
|
||||
css=["css/svgtogcode.css", "css/mrbeam.css"]
|
||||
)
|
||||
|
|
|
|||
BIN
src/octoprint/plugins/svgtogcode/static/img/wa_preview/0.jpg
Normal file
|
After Width: | Height: | Size: 184 KiB |
BIN
src/octoprint/plugins/svgtogcode/static/img/wa_preview/1.jpg
Normal file
|
After Width: | Height: | Size: 5 MiB |
BIN
src/octoprint/plugins/svgtogcode/static/img/wa_preview/10.jpg
Normal file
|
After Width: | Height: | Size: 5.9 MiB |
BIN
src/octoprint/plugins/svgtogcode/static/img/wa_preview/11.jpg
Normal file
|
After Width: | Height: | Size: 5.1 MiB |
BIN
src/octoprint/plugins/svgtogcode/static/img/wa_preview/12.jpg
Normal file
|
After Width: | Height: | Size: 4.4 MiB |
BIN
src/octoprint/plugins/svgtogcode/static/img/wa_preview/2.jpg
Normal file
|
After Width: | Height: | Size: 7.9 MiB |
BIN
src/octoprint/plugins/svgtogcode/static/img/wa_preview/3.jpg
Normal file
|
After Width: | Height: | Size: 8.3 MiB |
BIN
src/octoprint/plugins/svgtogcode/static/img/wa_preview/4.jpg
Normal file
|
After Width: | Height: | Size: 8.7 MiB |
BIN
src/octoprint/plugins/svgtogcode/static/img/wa_preview/5.jpg
Normal file
|
After Width: | Height: | Size: 8.3 MiB |
BIN
src/octoprint/plugins/svgtogcode/static/img/wa_preview/6.jpg
Normal file
|
After Width: | Height: | Size: 5.7 MiB |
BIN
src/octoprint/plugins/svgtogcode/static/img/wa_preview/7.jpg
Normal file
|
After Width: | Height: | Size: 7.4 MiB |
BIN
src/octoprint/plugins/svgtogcode/static/img/wa_preview/8.jpg
Normal file
|
After Width: | Height: | Size: 7.6 MiB |
BIN
src/octoprint/plugins/svgtogcode/static/img/wa_preview/9.jpg
Normal file
|
After Width: | Height: | Size: 8 MiB |
158
src/octoprint/plugins/svgtogcode/static/js/extrude.js
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
// extrude.js - a snapsvg.io plugin to generate extrusion walls of svg paths.
|
||||
// Copyright (C) 2016 Teja Philipp <osd@tejaphilipp.de>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
|
||||
Snap.plugin(function (Snap, Element, Paper, global) {
|
||||
|
||||
/**
|
||||
* @param {elem} elem start point
|
||||
*
|
||||
* @returns {path}
|
||||
*/
|
||||
|
||||
Element.prototype.extrude = function(height, perforation_curvature_threshold){
|
||||
var subdiv_length = 1;
|
||||
var material_thickness = 1;
|
||||
var perforation_curvature_threshold = perforation_curvature_threshold || 5;
|
||||
var elem = this;
|
||||
var walls = [];
|
||||
var children = elem.children();
|
||||
|
||||
if (children.length > 0) {
|
||||
var goRecursive = (elem.type !== "defs" && // ignore these tags
|
||||
elem.type !== "clipPath" &&
|
||||
elem.type !== "metadata" &&
|
||||
elem.type !== "rdf:rdf" &&
|
||||
elem.type !== "cc:work" &&
|
||||
elem.type !== "sodipodi:namedview");
|
||||
|
||||
if(goRecursive) {
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
var child = children[i];
|
||||
var more = child.extrude(height);
|
||||
walls.push.apply(walls, more);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var e;
|
||||
if (elem.type !== "path"){
|
||||
console.log('converting element to path', elem.type);
|
||||
e = elem.toPath();
|
||||
} else {
|
||||
e = elem;
|
||||
}
|
||||
|
||||
var dOriginal = e.attr('d');
|
||||
var parts = Snap.path.toRelative(dOriginal).toString();
|
||||
var segments = parts.split('m');
|
||||
|
||||
console.log('d',dOriginal);
|
||||
for (var i = 0; i < segments.length; i++) {
|
||||
if(segments[i].trim() !== ''){
|
||||
var seg = 'M' + segments[i];
|
||||
var l = Snap.path.getTotalLength(seg);
|
||||
console.log("segment", seg, l);
|
||||
walls.push(createWrappingPath2(seg), height);
|
||||
}
|
||||
}
|
||||
|
||||
//walls.push( createWrappingPath(segments, height));
|
||||
}
|
||||
return walls;
|
||||
};
|
||||
|
||||
function createWrappingPath2(segment, height){
|
||||
var l = Snap.path.getTotalLength(segment);
|
||||
console.log(segment, l);
|
||||
|
||||
// create "rectangle"
|
||||
var rect_d = "m0,0 l"+l+',0' // top
|
||||
+ ' l0,'+height // right
|
||||
+ ' l-'+l+',0' // bottom
|
||||
+ ' l0,-'+height; // left
|
||||
|
||||
var perforations = getPerforations(segment, 5);
|
||||
var perf_d = [];
|
||||
for (var i = 0; i < perforations.length; i++) {
|
||||
var perf = perforations[i];
|
||||
var density = 0.8 * perf.curvature/90;
|
||||
perf_d.push(createVerticalPerforation(perf.loc,height,density, height/10));
|
||||
|
||||
}
|
||||
return rect_d+perf_d.join(',');
|
||||
|
||||
}
|
||||
|
||||
function getPerforations(d, perf_curvature_threshold){
|
||||
var stepSize = 1;
|
||||
var perfs = [];
|
||||
var e = snap.path(d)
|
||||
var l = e.getTotalLength();
|
||||
var i = 0;
|
||||
var last_alpha = -999;
|
||||
var curvature_sum = 0;
|
||||
while(i<l){
|
||||
var p = e.getPointAtLength(i);
|
||||
p.curvature = last_alpha - p.alpha;
|
||||
p.loc = i;
|
||||
curvature_sum += p.curvature;
|
||||
last_alpha = p.alpha;
|
||||
if(Math.abs(curvature_sum) > perf_curvature_threshold){
|
||||
perfs.push({loc:i, curve:p.curvature});
|
||||
curvature_sum = 0;
|
||||
}
|
||||
i+=stepSize;
|
||||
}
|
||||
return perfs;
|
||||
}
|
||||
|
||||
function createWrappingPath(divs, height){
|
||||
var upper_d = "M0,0";
|
||||
var lower_d = "M0,"+height;
|
||||
var verticals = ['M0,0l0,'+height];
|
||||
for (var i = 0; i < divs.length; i++) {
|
||||
var d = divs[i];
|
||||
var x = d.loc.toFixed(2);
|
||||
upper_d += 'L'+x+',0';
|
||||
lower_d += 'L'+x+','+height;
|
||||
var density = 0.8* d.curvature/180;
|
||||
verticals.push(createVerticalPerforation(x,height, density, height/15));
|
||||
}
|
||||
return upper_d+lower_d+verticals.join();
|
||||
}
|
||||
|
||||
function createVerticalPerforation(x, height, density, perfLength){
|
||||
var cut = (perfLength * (density)).toFixed(2);
|
||||
var gap = (perfLength - cut).toFixed(2);
|
||||
var d = 'M'+x+',0';
|
||||
var y = 0;
|
||||
while(y < height){
|
||||
d += 'l0,'+cut+'m0,'+gap;
|
||||
y += perfLength;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -9,13 +9,26 @@
|
|||
|
||||
{% include 'stylesheets.jinja2' %}
|
||||
{% include 'initscript.jinja2' %}
|
||||
|
||||
<script type="text/javascript" >
|
||||
function cycle_bg(){
|
||||
var path = $('#cam').attr('xlink:href');
|
||||
var m = path.match(/[0-9]+/);
|
||||
var number = 0;
|
||||
if(m.length > 0){
|
||||
number = (parseInt(m[0]) + 1) % 12;
|
||||
}
|
||||
var nPath = "/plugin/svgtogcode/static/img/wa_preview/" + number + ".jpg";
|
||||
$('#cam').attr('xlink:href', nPath);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container octoprint-container">
|
||||
<nav class="navbar navbar-default navbar-fixed-top" role="navigation" id="navbar">
|
||||
<div class="container">
|
||||
<div class="navbar-header brand" style="min-width: 272px;">
|
||||
<a class="navbar-brand" href="#">
|
||||
<div class="navbar-header brand" style="min-width: 272px;" onclick="cycle_bg()">
|
||||
<a class="navbar-brand" href="#" >
|
||||
<img alt="Mr Beam Logo" src="{{ url_for('static', filename='img/mr-typo-red_x120.png') }}">
|
||||
</a>
|
||||
</div>
|
||||
|
|
@ -316,6 +329,9 @@
|
|||
<feFuncB type="table" tableValues="0.2 1"></feFuncB>
|
||||
</feComponentTransfer>
|
||||
</filter>
|
||||
<image id="cam" xlink:href="/plugin/svgtogcode/static/img/wa_preview/0.jpg" x="0" y="0"
|
||||
height="0px" width="0px" data-bind="attr: { width: workingAreaWidthPx()+'px', height: workingAreaHeightPx()+'px'}" />
|
||||
|
||||
<g id="scaleGroup" data-bind="attr: { transform: scaleMatrix() }">
|
||||
|
||||
<text
|
||||
|
|
|
|||
|
|
@ -347,6 +347,7 @@ class MachineCom(object):
|
|||
def _handle_ok_message(self):
|
||||
if self._state == self.STATE_HOMING:
|
||||
self._changeState(self.STATE_OPERATIONAL)
|
||||
self._onHomingDone()
|
||||
|
||||
def _handle_error_message(self, line):
|
||||
self._errorValue = line
|
||||
|
|
@ -539,6 +540,11 @@ class MachineCom(object):
|
|||
payload = dict(port=self._port, baudrate=self._baudrate)
|
||||
eventManager().fire(Events.CONNECTED, payload)
|
||||
|
||||
def _onHomingDone(self):
|
||||
self.sendCommand("G92X500Y0Z0")
|
||||
self.sendCommand("G90")
|
||||
self.sendCommand("G21")
|
||||
|
||||
def _detectPort(self, close):
|
||||
self._log("Serial port list: %s" % (str(serialList())))
|
||||
for p in serialList():
|
||||
|
|
|
|||