Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessandro Ranellucci <aar@cpan.org>2011-09-18 21:28:12 +0400
committerAlessandro Ranellucci <aar@cpan.org>2011-09-18 21:28:12 +0400
commit18c7aef1a74e4be3ffe1160e00d7d19455f4e62e (patch)
treee7db4ea2eea7e7b30c2b9c387da01454571e9ca3 /lib/Slic3r/SVG.pm
parent26b05ab155046c4c04fc326aa6d9d00ffc799270 (diff)
Lots of changes and refactoring after testing with hollow objects
Diffstat (limited to 'lib/Slic3r/SVG.pm')
-rw-r--r--lib/Slic3r/SVG.pm86
1 files changed, 86 insertions, 0 deletions
diff --git a/lib/Slic3r/SVG.pm b/lib/Slic3r/SVG.pm
new file mode 100644
index 000000000..b7c7e5199
--- /dev/null
+++ b/lib/Slic3r/SVG.pm
@@ -0,0 +1,86 @@
+package Slic3r::SVG;
+use strict;
+use warnings;
+
+use SVG;
+
+use constant X => 0;
+use constant Y => 1;
+
+sub factor {
+ return $Slic3r::resolution * 10;
+}
+
+sub svg {
+ my ($print) = @_;
+
+ return SVG->new(width => $print->max_length * factor(), height => $print->max_length * factor());
+}
+
+sub output_polygons {
+ my ($print, $filename, $polygons) = @_;
+
+ my $svg = svg($print);
+ my $g = $svg->group(
+ style => {
+ 'stroke-width' => 2,
+ },
+ );
+ foreach my $polygon (@$polygons) {
+ my $path = $svg->get_path(
+ 'x' => [ map($_->[X] * factor(), @$polygon) ],
+ 'y' => [ map($_->[Y] * factor(), @$polygon) ],
+ -type => 'polygon',
+ );
+ $g->polygon(
+ %$path,
+ );
+ }
+
+ write_svg($svg, $filename);
+}
+
+sub output_lines {
+ my ($print, $filename, $lines) = @_;
+
+ my $svg = svg($print);
+ my $g = $svg->group(
+ style => {
+ 'stroke-width' => 2,
+ },
+ );
+
+ my $color = 'red';
+ my $draw_line = sub {
+ my ($line) = @_;
+ $g->line(
+ x1 => $line->[0][X] * factor(),
+ y1 => $line->[0][Y] * factor(),
+ x2 => $line->[1][X] * factor(),
+ y2 => $line->[1][Y] * factor(),
+ style => {
+ 'stroke' => $color,
+ },
+ );
+ };
+
+ my $last = pop @$lines;
+ foreach my $line (@$lines) {
+ $draw_line->($line);
+ }
+ $color = 'black';
+ $draw_line->($last);
+
+ write_svg($svg, $filename);
+}
+
+sub write_svg {
+ my ($svg, $filename) = @_;
+
+ open my $fh, '>', $filename;
+ print $fh $svg->xmlify;
+ close $fh;
+ printf "SVG written to %s\n", $filename;
+}
+
+1;