Export plates as AMF constellations

This commit is contained in:
Alessandro Ranellucci 2012-08-29 17:11:56 +02:00
parent f90520ed06
commit 23f6842bd4
3 changed files with 55 additions and 8 deletions

View File

@ -56,6 +56,7 @@ sub write_file {
} }
printf $fh qq{ </material>\n}; printf $fh qq{ </material>\n};
} }
my $instances = '';
for my $object_id (0 .. $#{ $model->objects }) { for my $object_id (0 .. $#{ $model->objects }) {
my $object = $model->objects->[$object_id]; my $object = $model->objects->[$object_id];
printf $fh qq{ <object id="%d">\n}, $object_id; printf $fh qq{ <object id="%d">\n}, $object_id;
@ -76,13 +77,27 @@ sub write_file {
(!defined $volume->material_id) ? '' : (sprintf ' materialid="%s"', $volume->material_id); (!defined $volume->material_id) ? '' : (sprintf ' materialid="%s"', $volume->material_id);
foreach my $facet (@{$volume->facets}) { foreach my $facet (@{$volume->facets}) {
printf $fh qq{ <triangle>\n}; printf $fh qq{ <triangle>\n};
printf $fh qq{ <v%d>%d</v%d>\n}, $_, $facet->[$_], $_ for -3..-1; printf $fh qq{ <v%d>%d</v%d>\n}, (4+$_), $facet->[$_], (4+$_) for -3..-1;
printf $fh qq{ </triangle>\n}; printf $fh qq{ </triangle>\n};
} }
printf $fh qq{ </volume>\n}; printf $fh qq{ </volume>\n};
} }
printf $fh qq{ </mesh>\n}; printf $fh qq{ </mesh>\n};
printf $fh qq{ </object>\n}; printf $fh qq{ </object>\n};
if ($object->instances) {
foreach my $instance (@{$object->instances}) {
$instances .= sprintf qq{ <instance objectid="%d">\n}, $object_id;
$instances .= sprintf qq{ <deltax>%s</deltax>\n}, $instance->offset->[X];
$instances .= sprintf qq{ <deltax>%s</deltax>\n}, $instance->offset->[Y];
$instances .= sprintf qq{ <rz>%s</rz>\n}, $instance->rotation;
$instances .= sprintf qq{ </instance>\n};
}
}
}
if ($instances) {
printf $fh qq{ <constellation id="1">\n};
printf $fh $instances;
printf $fh qq{ </constellation>\n};
} }
printf $fh qq{</amf>\n}; printf $fh qq{</amf>\n};
close $fh; close $fh;

View File

@ -22,6 +22,10 @@ use constant MI_REPEAT_QUICK => &Wx::NewId;
use constant MI_QUICK_SAVE_AS => &Wx::NewId; use constant MI_QUICK_SAVE_AS => &Wx::NewId;
use constant MI_SLICE_SVG => &Wx::NewId; use constant MI_SLICE_SVG => &Wx::NewId;
use constant MI_PLATER_EXPORT_GCODE => &Wx::NewId;
use constant MI_PLATER_EXPORT_STL => &Wx::NewId;
use constant MI_PLATER_EXPORT_AMF => &Wx::NewId;
use constant MI_TAB_PLATER => &Wx::NewId; use constant MI_TAB_PLATER => &Wx::NewId;
use constant MI_TAB_PRINT => &Wx::NewId; use constant MI_TAB_PRINT => &Wx::NewId;
use constant MI_TAB_FILAMENT => &Wx::NewId; use constant MI_TAB_FILAMENT => &Wx::NewId;
@ -98,6 +102,17 @@ sub OnInit {
EVT_MENU($frame, wxID_EXIT, sub {$_[0]->Close(0)}); EVT_MENU($frame, wxID_EXIT, sub {$_[0]->Close(0)});
} }
# Plater menu
my $platerMenu = Wx::Menu->new;
{
$platerMenu->Append(MI_PLATER_EXPORT_GCODE, "Export G-code...", 'Export current plate as G-code');
$platerMenu->Append(MI_PLATER_EXPORT_STL, "Export STL...", 'Export current plate as STL');
$platerMenu->Append(MI_PLATER_EXPORT_AMF, "Export AMF...", 'Export current plate as AMF');
EVT_MENU($frame, MI_PLATER_EXPORT_GCODE, sub { $self->{skeinpanel}{plater}->export_gcode });
EVT_MENU($frame, MI_PLATER_EXPORT_STL, sub { $self->{skeinpanel}{plater}->export_stl });
EVT_MENU($frame, MI_PLATER_EXPORT_AMF, sub { $self->{skeinpanel}{plater}->export_amf });
}
# Window menu # Window menu
my $windowMenu = Wx::Menu->new; my $windowMenu = Wx::Menu->new;
{ {
@ -128,6 +143,7 @@ sub OnInit {
{ {
my $menubar = Wx::MenuBar->new; my $menubar = Wx::MenuBar->new;
$menubar->Append($fileMenu, "&File"); $menubar->Append($fileMenu, "&File");
$menubar->Append($platerMenu, "&Plater");
$menubar->Append($windowMenu, "&Window"); $menubar->Append($windowMenu, "&Window");
$menubar->Append($helpMenu, "&Help"); $menubar->Append($helpMenu, "&Help");
$frame->SetMenuBar($menubar); $frame->SetMenuBar($menubar);

View File

@ -631,23 +631,39 @@ sub on_export_failed {
sub export_stl { sub export_stl {
my $self = shift; my $self = shift;
# select output file my $output_file = $self->_get_export_file('STL') or return;
Slic3r::Format::STL->write_file($output_file, $self->make_model, binary => 1);
$self->statusbar->SetStatusText("STL file exported to $output_file");
}
sub export_amf {
my $self = shift;
my $output_file = $self->_get_export_file('AMF') or return;
Slic3r::Format::AMF->write_file($output_file, $self->make_model);
$self->statusbar->SetStatusText("AMF file exported to $output_file");
}
sub _get_export_file {
my $self = shift;
my ($format) = @_;
my $suffix = $format eq 'STL' ? '.stl' : '.amf.xml';
my $output_file = $main::opt{output}; my $output_file = $main::opt{output};
{ {
$output_file = $self->{print}->expanded_output_filepath($output_file); $output_file = $self->{print}->expanded_output_filepath($output_file);
$output_file =~ s/\.gcode$/.stl/i; $output_file =~ s/\.gcode$/$suffix/i;
my $dlg = Wx::FileDialog->new($self, 'Save STL file as:', dirname($output_file), my $dlg = Wx::FileDialog->new($self, "Save $format file as:", dirname($output_file),
basename($output_file), $Slic3r::GUI::SkeinPanel::model_wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT); basename($output_file), $Slic3r::GUI::SkeinPanel::model_wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
if ($dlg->ShowModal != wxID_OK) { if ($dlg->ShowModal != wxID_OK) {
$dlg->Destroy; $dlg->Destroy;
return; return undef;
} }
$output_file = $Slic3r::GUI::SkeinPanel::last_output_file = $dlg->GetPath; $output_file = $Slic3r::GUI::SkeinPanel::last_output_file = $dlg->GetPath;
$dlg->Destroy; $dlg->Destroy;
} }
return $output_file;
Slic3r::Format::STL->write_file($output_file, $self->make_model, binary => 1);
$self->statusbar->SetStatusText("STL file exported to $output_file");
} }
sub make_model { sub make_model {