mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-10-20 13:01:09 +08:00

* Include Miniz library in xs/src/miniz and update CMakeLists.txt in /src * Save porgress before merging from Slic3r upstream * Add CLI --export-3mf option. * Create the TMF Class. * call IO::TMF:write function with the read model and the output file in slic3r.cpp Fix miniz.c error: * Miniz source functions were included more than once (once during TMF.cpp and once during compiling miniz.c in /xs/src/miniz. * Miniz is a header file library. * Solution was to add #define MINIZ_HEADER_FILE_ONLY to include the header part of the single header library miniz.c. * - Create a Zip archive contating a 3dmodel.model file conatining a basic string. - Remove #define #define MINIZ_HEADER_FILE_ONLY in the previous commit ( It's not the solution) * Write Model metadata element to the 3MF zip file. * Renaming miniz.c to miniz.h, if you want to include it in other file use #define MINIZ_HEADER_FILE_ONLY before including it. * Adding zip lib as a wrapper * Adding zip lib files * Fix CMakeLists.txt zip library error: Add zip lib to target_link_libraries. * Add 3MF Read/Write Structure. I think this makes TMF read/write more modular. * Fix some errors in TMF.cpp * Write ModelMaterial according to 3MF core specification. fix some typos and variable names. * Add 3MF Types and OPC relationships. * Write types in "[Content_Types].xml" at / * Create "_rels" folder at / * Write for each Object its mesh vertices element in 3MF Document. * Write Model Volumes of each object in the 3MF Document. * write <triangles> element representing the volumes of each object. * * Refactoring removed Camel Case style. * Adding ModelObject part number attribute (Specific to the new 3MF format). * Write 3MF Relationships in the zip archive. * * Remove the first extension from the exported file name. * Add partnumber to the constructor. * Fix ContentTypes.xml file causing 3D Builder not to load the file. * xmlns schema link added to < Types > element. * * Write Slic3r metadata version. * Write ModelMaterials custom config data. * * Write ModelObject Slic3r custom configs data. * Some Refactoring. * * Write ModelVolume Sli3r custom configs to the 3MF Document. * * Write ModelInstances to the 3MF Document and small refactoring * * Fix ModelInstance transformation matrix in < build > element. The problem was that 3MF 3d matrices were row major matrices. * Some Refactoring: * Add namspaces as constant map<string, string> carrying name of namspace and the link to the namespace. * *Fix std::map namespaces. I was using [] operator to access the map values but according to c++11 I must use .at(key) to compile. * * Write colorgroup elements in Material Extension to 3MF core specs: * Created color_group attribute in Model class. * Created material_group attribute in ModelMaterial class. It's by default 0 whuch means basematerial or AMF read material. * * Fix CMakeLists.txt zip target link libraries. * Add data structure for 3MF Material Extension. * Fix slic3r.cpp whitespace issues. * Split TMFEditor class into TMF.hpp and TMF.cpp files * Remove color groups attribute and put all material groups in the 3MF extension into one structure. * Fix temprory Zip lib. Modify TMFEditor class pivate and public memebers. * Some Refactoring. Make remove any extension not just the last one. * Add a unit test case for write function. Some refactoring * Fix some issues found in the basic 3mf unit test case for TMF::write. * Forget to change 2 lines in 23_3mf.t * Some Refactoring * Remove basename function in zip.c hoping the build pass. Refactoring in the 23_3mf.t * Add another test case for wrting a model containing materials. * Add SplitPyramid.amf test file in xs/t/amf * Add basic TMFParserContext struct for reading 3MF XML model file. * Add Expat handlers. * Add member functions to TMFParserContext struc: startElement, endElement, characters and stop. * Add 3mf extension to Model::read_from_file function Ajust comments according to Doxygen syntax * * ad model metadata * Extract the 3dmodel.model file to disc. * Read the extracted file using Expat XML er. * Read basematerials found in the 3MF core specifications. Fix some errors in reading metadata. Add TMFEditor::read_model() function. * Change material data structure to include all 3MF materials including (basematerials, m:colorgroups, etc) * Read Object vertices. Fix errors during reading basematerial. * Read object mesh. * Some Refactoring in TMFParserContext and TMF::Editor * Read Objects (Objects with meshes, and objects containing other objects -components-) * Read Build items (ModelInstances) without applying transformations yet. * * Read scale and translations values from the transformation affine matrix found in the component tag. * Some refactoring * Get the rotaion Euler angles from the transformation matrix. * Fix to get_transformation * Fix metadata lost due to not copying them in the copy constructor. * Read Slic3r custom config keys for ModelObjects. Modify write Slic3r custom configs for ModelObject * Read Slic3r custom configs of ModelVolumes. * Refactor applying tranformation matri * Fix in reading 3mf format where wrong objects are deleted from the model * Fix in 3MF read: When reading component tags. When adding a component to the current object we first copy the object refered by objectid in component tag, then apply transformation to the copied object then get the mesh of that object and finally delete this object copy and add that mesh to the current object. * Write model metadata in descending order to make title appear first. * Refactoring: Remove all assertions in 3MF read and replace it with TMFParserContext::stop() as if assertion fails the extracted 3dmodel.model file won't be deleted. * Read basematerials in the original model materials map. Remove the added model material groups. * Fix fatal error in adding volume when reading 3MF model file. The end offset should be equal to the size of facets minus one. * Read color groups. * some refactoring * * Some fixes. * Add model instance x, y rotations and (x,y,z) scaling.(Still working on them). * Add translation z in the model instance. Add x, y rotation to the model instance copy constructor. * Fixes in writing slicer:volume tag * Remove some todos. * Improve write materials to adopt groups * Some Fixes * Some Fixes * Read Slic3r materials custom print configs. * Add basic test for 3mf read. * Add another test for TMF::read(). * Revert change in slic3r.pl file and removed .DS_store files * Use initialize list in TMFEditor constructor. Add a new line in the end of slic3r.cpp * Add partnumber to ModelObject::swap() function called by assignment operator. * Deleted xs/t/3mf/.DS_Store * Removed appling 3mf translation in the z_axis to the model instances. * Add X&Y rotations, z_translation in 3D, 3D previews and layers plater. To be applied when duplicating objects, etc. * Add the parent object part number to the split objects. * Initialize Model metadata. Add 2 STL test files. Add all 3d model test files in xs/models folder. * Add 3mf test (convert from/to STL). Add partnumber in Model.xsp * Changed material groups enum to scoped enums. Fix a typo in 23_3mf.t * Fix in 23_3mf.test. * Include X&Y rotation angles, scaling vector in the transformation matrix in item tag. * Add 3MF file extension to GUI. * Fix reading slic3r:volume tag in 3mf document. * Add X&Y rotations, scaling vecotr in the 2D platter. Those 3mf transformation parameters are applied in 2D, 3D, 3D preview and 2D toolpaths platters. * Remove support for 3MF materials. The materials in 3mf are found at the object level and at the triangle level but not found at the volume level. They are not really useful in our case. * Remove some warnings and add transformation matrix test. * Remove headers included for IDE suggestions * Some enhancements * Some enhancements * Fix a bug. * Remove hardcoded Slic3r version & some enhancements. * Add another test to 3mf and some enhancements. * Remove models which became not used in 3mf tests. * Small change in apply_transformation for model instance in tmf.cpp. * Some Refactoring to TMF.cpp * Remove size_t in for loops and use const auto ModelObject or ModelVolume in TMFEditor::write() Some refactoring. * Use nullptr instead of NULL in TMFEditor. * Initialize TMFParserContext data memebers instead of calling std::vector clear() function. * Fix a typo caused by refactoring * Add Export plate with modifiers as 3MF and Export object with modifiers as 3MF options to Slic3r GUI. * * Remove zip library. * Add Slic3r::ZipArchive class to handle creating zip files. * Add extract_entry function to ZipArchive class * * Modify TMF::write to adapt the new zip wrapper. * Improvements in ZipArchive. * * Improve TMFEditor:write by removing to_string template function aw we are using now ofstream. * * Split ZipArchive class to .cpp and .hpp * Add Doxygen documentation to ZipArchive class. * Update MANIFEST file/ * Update CMakeLists.txt file * * Some improvements to ZipArchive. * Fix the failing 3MF test on windows.The problem was the end line is manipulated on windows as \r\n * Add 3mf test files to MANIFEST file.
317 lines
11 KiB
Perl
317 lines
11 KiB
Perl
# The bed shape dialog.
|
||
# The dialog opens from Print Settins tab -> Bed Shape: Set...
|
||
|
||
package Slic3r::GUI::BedShapeDialog;
|
||
use strict;
|
||
use warnings;
|
||
use utf8;
|
||
|
||
use List::Util qw(min max);
|
||
use Slic3r::Geometry qw(PI X Y unscale);
|
||
use Wx qw(:dialog :id :misc :sizer :choicebook wxTAB_TRAVERSAL);
|
||
use Wx::Event qw(EVT_CLOSE);
|
||
use base 'Wx::Dialog';
|
||
|
||
sub new {
|
||
my $class = shift;
|
||
my ($parent, $default) = @_;
|
||
my $self = $class->SUPER::new($parent, -1, "Bed Shape", wxDefaultPosition, [350,700], wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER);
|
||
|
||
$self->{panel} = my $panel = Slic3r::GUI::BedShapePanel->new($self, $default);
|
||
|
||
my $main_sizer = Wx::BoxSizer->new(wxVERTICAL);
|
||
$main_sizer->Add($panel, 1, wxEXPAND);
|
||
$main_sizer->Add($self->CreateButtonSizer(wxOK | wxCANCEL), 0, wxEXPAND);
|
||
|
||
$self->SetSizer($main_sizer);
|
||
$self->SetMinSize($self->GetSize);
|
||
$main_sizer->SetSizeHints($self);
|
||
|
||
# needed to actually free memory
|
||
EVT_CLOSE($self, sub {
|
||
$self->EndModal(wxID_OK);
|
||
$self->Destroy;
|
||
});
|
||
|
||
return $self;
|
||
}
|
||
|
||
sub GetValue {
|
||
my ($self) = @_;
|
||
return $self->{panel}->GetValue;
|
||
}
|
||
|
||
package Slic3r::GUI::BedShapePanel;
|
||
|
||
use List::Util qw(min max sum first);
|
||
use Scalar::Util qw(looks_like_number);
|
||
use Slic3r::Geometry qw(PI X Y scale unscale scaled_epsilon deg2rad);
|
||
use Wx qw(:font :id :misc :sizer :choicebook :filedialog :pen :brush wxTAB_TRAVERSAL);
|
||
use Wx::Event qw(EVT_CLOSE EVT_CHOICEBOOK_PAGE_CHANGED EVT_BUTTON);
|
||
use base 'Wx::Panel';
|
||
|
||
use constant SHAPE_RECTANGULAR => 0;
|
||
use constant SHAPE_CIRCULAR => 1;
|
||
use constant SHAPE_CUSTOM => 2;
|
||
|
||
sub new {
|
||
my $class = shift;
|
||
my ($parent, $default) = @_;
|
||
my $self = $class->SUPER::new($parent, -1);
|
||
|
||
$self->on_change(undef);
|
||
|
||
my $box = Wx::StaticBox->new($self, -1, "Shape");
|
||
my $sbsizer = Wx::StaticBoxSizer->new($box, wxVERTICAL);
|
||
|
||
# shape options
|
||
$self->{shape_options_book} = Wx::Choicebook->new($self, -1, wxDefaultPosition, [300,-1], wxCHB_TOP);
|
||
$sbsizer->Add($self->{shape_options_book});
|
||
|
||
$self->{optgroups} = [];
|
||
{
|
||
my $optgroup = $self->_init_shape_options_page('Rectangular');
|
||
$optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
|
||
opt_id => 'rect_size',
|
||
type => 'point',
|
||
label => 'Size',
|
||
tooltip => 'Size in X and Y of the rectangular plate.',
|
||
default => [200,200],
|
||
));
|
||
$optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
|
||
opt_id => 'rect_origin',
|
||
type => 'point',
|
||
label => 'Origin',
|
||
tooltip => 'Distance of the 0,0 G-code coordinate from the front left corner of the rectangle.',
|
||
default => [0,0],
|
||
));
|
||
}
|
||
{
|
||
my $optgroup = $self->_init_shape_options_page('Circular');
|
||
$optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
|
||
opt_id => 'diameter',
|
||
type => 'f',
|
||
label => 'Diameter',
|
||
tooltip => 'Diameter of the print bed. It is assumed that origin (0,0) is located in the center.',
|
||
sidetext => 'mm',
|
||
default => 200,
|
||
));
|
||
}
|
||
{
|
||
my $optgroup = $self->_init_shape_options_page('Custom');
|
||
$optgroup->append_line(Slic3r::GUI::OptionsGroup::Line->new(
|
||
full_width => 1,
|
||
widget => sub {
|
||
my ($parent) = @_;
|
||
|
||
my $btn = Wx::Button->new($parent, -1, "Load shape from STL...", wxDefaultPosition, wxDefaultSize);
|
||
EVT_BUTTON($self, $btn, sub { $self->_load_stl });
|
||
return $btn;
|
||
}
|
||
));
|
||
}
|
||
|
||
EVT_CHOICEBOOK_PAGE_CHANGED($self, -1, sub {
|
||
$self->_update_shape;
|
||
});
|
||
|
||
# right pane with preview canvas
|
||
my $canvas = $self->{canvas} = Slic3r::GUI::2DBed->new($self);
|
||
|
||
# main sizer
|
||
my $top_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
|
||
$top_sizer->Add($sbsizer, 0, wxEXPAND | wxTOP | wxBOTTOM, 10);
|
||
$top_sizer->Add($canvas, 1, wxEXPAND | wxALL, 10) if $canvas;
|
||
|
||
$self->SetSizerAndFit($top_sizer);
|
||
|
||
$self->_set_shape($default);
|
||
$self->_update_preview;
|
||
|
||
return $self;
|
||
}
|
||
|
||
sub on_change {
|
||
my ($self, $cb) = @_;
|
||
$self->{on_change} = $cb // sub {};
|
||
}
|
||
|
||
# Called from the constructor.
|
||
# Set the initial bed shape from a list of points.
|
||
# Deduce the bed shape type (rect, circle, custom)
|
||
# This routine shall be smart enough if the user messes up
|
||
# with the list of points in the ini file directly.
|
||
sub _set_shape {
|
||
my ($self, $points) = @_;
|
||
|
||
# is this a rectangle?
|
||
if (@$points == 4) {
|
||
my $polygon = Slic3r::Polygon->new_scale(@$points);
|
||
my $lines = $polygon->lines;
|
||
if ($lines->[0]->parallel_to_line($lines->[2]) && $lines->[1]->parallel_to_line($lines->[3])) {
|
||
# okay, it's a rectangle
|
||
|
||
# find origin
|
||
# the || 0 hack prevents "-0" which might confuse the user
|
||
my $x_min = min(map $_->[X], @$points) || 0;
|
||
my $x_max = max(map $_->[X], @$points) || 0;
|
||
my $y_min = min(map $_->[Y], @$points) || 0;
|
||
my $y_max = max(map $_->[Y], @$points) || 0;
|
||
my $origin = [-$x_min, -$y_min];
|
||
|
||
$self->{shape_options_book}->SetSelection(SHAPE_RECTANGULAR);
|
||
my $optgroup = $self->{optgroups}[SHAPE_RECTANGULAR];
|
||
$optgroup->set_value('rect_size', [ $x_max-$x_min, $y_max-$y_min ]);
|
||
$optgroup->set_value('rect_origin', $origin);
|
||
$self->_update_shape;
|
||
return;
|
||
}
|
||
}
|
||
|
||
# is this a circle?
|
||
{
|
||
# Analyze the array of points. Do they reside on a circle?
|
||
my $polygon = Slic3r::Polygon->new_scale(@$points);
|
||
my $center = $polygon->bounding_box->center;
|
||
my @vertex_distances = map $center->distance_to($_), @$polygon;
|
||
my $avg_dist = sum(@vertex_distances)/@vertex_distances;
|
||
if (!defined first { abs($_ - $avg_dist) > 10*scaled_epsilon } @vertex_distances) {
|
||
# all vertices are equidistant to center
|
||
$self->{shape_options_book}->SetSelection(SHAPE_CIRCULAR);
|
||
my $optgroup = $self->{optgroups}[SHAPE_CIRCULAR];
|
||
$optgroup->set_value('diameter', sprintf("%.0f", unscale($avg_dist*2)));
|
||
$self->_update_shape;
|
||
return;
|
||
}
|
||
}
|
||
|
||
if (@$points < 3) {
|
||
# Invalid polygon. Revert to default bed dimensions.
|
||
$self->{shape_options_book}->SetSelection(SHAPE_RECTANGULAR);
|
||
my $optgroup = $self->{optgroups}[SHAPE_RECTANGULAR];
|
||
$optgroup->set_value('rect_size', [200, 200]);
|
||
$optgroup->set_value('rect_origin', [0, 0]);
|
||
$self->_update_shape;
|
||
return;
|
||
}
|
||
|
||
# This is a custom bed shape, use the polygon provided.
|
||
$self->{shape_options_book}->SetSelection(SHAPE_CUSTOM);
|
||
# Copy the polygon to the canvas, make a copy of the array.
|
||
$self->{canvas}->bed_shape([@$points]);
|
||
$self->_update_shape;
|
||
}
|
||
|
||
# Update the bed shape from the dialog fields.
|
||
sub _update_shape {
|
||
my ($self) = @_;
|
||
|
||
my $page_idx = $self->{shape_options_book}->GetSelection;
|
||
if ($page_idx == SHAPE_RECTANGULAR) {
|
||
my $rect_size = $self->{optgroups}[SHAPE_RECTANGULAR]->get_value('rect_size');
|
||
my $rect_origin = $self->{optgroups}[SHAPE_RECTANGULAR]->get_value('rect_origin');
|
||
my ($x, $y) = @$rect_size;
|
||
return if !looks_like_number($x) || !looks_like_number($y); # empty strings or '-' or other things
|
||
return if !$x || !$y or $x == 0 or $y == 0;
|
||
my ($x0, $y0) = (0,0);
|
||
my ($x1, $y1) = ($x ,$y);
|
||
{
|
||
my ($dx, $dy) = @$rect_origin;
|
||
return if !looks_like_number($dx) || !looks_like_number($dy); # empty strings or '-' or other things
|
||
$x0 -= $dx;
|
||
$x1 -= $dx;
|
||
$y0 -= $dy;
|
||
$y1 -= $dy;
|
||
}
|
||
$self->{canvas}->bed_shape([
|
||
[$x0,$y0],
|
||
[$x1,$y0],
|
||
[$x1,$y1],
|
||
[$x0,$y1],
|
||
]);
|
||
} elsif ($page_idx == SHAPE_CIRCULAR) {
|
||
my $diameter = $self->{optgroups}[SHAPE_CIRCULAR]->get_value('diameter');
|
||
return if !$diameter or $diameter == 0;
|
||
my $r = $diameter/2;
|
||
my $twopi = 2*PI;
|
||
my $edges = 60;
|
||
my $polygon = Slic3r::Polygon->new_scale(
|
||
map [ $r * cos $_, $r * sin $_ ],
|
||
map { $twopi/$edges*$_ } 1..$edges
|
||
);
|
||
$self->{canvas}->bed_shape([
|
||
map [ unscale($_->x), unscale($_->y) ], @$polygon #))
|
||
]);
|
||
}
|
||
|
||
$self->{on_change}->();
|
||
$self->_update_preview;
|
||
}
|
||
|
||
sub _update_preview {
|
||
my ($self) = @_;
|
||
$self->{canvas}->Refresh if $self->{canvas};
|
||
$self->Refresh;
|
||
}
|
||
|
||
# Called from the constructor.
|
||
# Create a panel for a rectangular / circular / custom bed shape.
|
||
sub _init_shape_options_page {
|
||
my ($self, $title) = @_;
|
||
|
||
my $panel = Wx::Panel->new($self->{shape_options_book});
|
||
my $optgroup;
|
||
push @{$self->{optgroups}}, $optgroup = Slic3r::GUI::OptionsGroup->new(
|
||
parent => $panel,
|
||
title => 'Settings',
|
||
label_width => 100,
|
||
on_change => sub {
|
||
my ($opt_id) = @_;
|
||
#$self->{"_$opt_id"} = $optgroup->get_value($opt_id);
|
||
$self->_update_shape;
|
||
},
|
||
);
|
||
$panel->SetSizerAndFit($optgroup->sizer);
|
||
$self->{shape_options_book}->AddPage($panel, $title);
|
||
|
||
return $optgroup;
|
||
}
|
||
|
||
# Loads an stl file, projects it to the XY plane and calculates a polygon.
|
||
sub _load_stl {
|
||
my ($self) = @_;
|
||
|
||
my $dialog = Wx::FileDialog->new($self, 'Choose a file to import bed shape from (STL/OBJ/AMF/3MF):', "", "", &Slic3r::GUI::MODEL_WILDCARD, wxFD_OPEN | wxFD_FILE_MUST_EXIST);
|
||
if ($dialog->ShowModal != wxID_OK) {
|
||
$dialog->Destroy;
|
||
return;
|
||
}
|
||
my $input_file = Slic3r::decode_path($dialog->GetPaths);
|
||
$dialog->Destroy;
|
||
|
||
my $model = Slic3r::Model->read_from_file($input_file);
|
||
my $mesh = $model->raw_mesh;
|
||
my $expolygons = $mesh->horizontal_projection;
|
||
|
||
if (@$expolygons == 0) {
|
||
Slic3r::GUI::show_error($self, "The selected file contains no geometry.");
|
||
return;
|
||
}
|
||
if (@$expolygons > 1) {
|
||
Slic3r::GUI::show_error($self, "The selected file contains several disjoint areas. This is not supported.");
|
||
return;
|
||
}
|
||
|
||
my $polygon = $expolygons->[0]->contour;
|
||
$self->{canvas}->bed_shape([ map [ unscale($_->x), unscale($_->y) ], @$polygon ]);
|
||
$self->_update_preview();
|
||
}
|
||
|
||
# Returns the resulting bed shape polygon. This value will be stored to the ini file.
|
||
sub GetValue {
|
||
my ($self) = @_;
|
||
return $self->{canvas}->bed_shape;
|
||
}
|
||
|
||
1;
|