Finished implementation of bed_shape in plater

This commit is contained in:
Alessandro Ranellucci 2014-06-16 15:18:39 +02:00
parent 7a20c4d52a
commit 998a4225de
10 changed files with 85 additions and 28 deletions

View file

@ -9,7 +9,7 @@ use List::Util qw(first max);
our @Ignore = qw(duplicate_x duplicate_y multiply_x multiply_y support_material_tool acceleration
adjust_overhang_flow standby_temperature scale rotate duplicate duplicate_grid
rotate scale duplicate_grid start_perimeters_at_concave_points start_perimeters_at_non_overhang
randomize_start seal_position);
randomize_start seal_position bed_size);
our $Options = print_config_def();
@ -23,7 +23,7 @@ $Options->{threads}{readonly} = !$Slic3r::have_threads;
*{$opt_key} = sub { $_[0]->get($opt_key) };
}
}
sub bed_size { [200,200] }
sub new_from_defaults {
my $class = shift;
my (@opt_keys) = @_;
@ -297,11 +297,6 @@ sub validate {
die "Invalid value for --infill-every-layers\n"
if $self->infill_every_layers !~ /^\d+$/ || $self->infill_every_layers < 1;
# --bed-size
die "Invalid value for --bed-size\n"
if !ref $self->bed_size
&& (!$self->bed_size || $self->bed_size !~ /^\d+,\d+$/);
# --skirt-height
die "Invalid value for --skirt-height\n"
if $self->skirt_height < -1; # -1 means as tall as the object

View file

@ -50,7 +50,7 @@ sub new {
my ($parent) = @_;
my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
$self->{config} = Slic3r::Config->new_from_defaults(qw(
bed_size bed_shape print_center complete_objects extruder_clearance_radius skirts skirt_distance
bed_shape print_center complete_objects extruder_clearance_radius skirts skirt_distance
));
$self->{model} = Slic3r::Model->new;
$self->{print} = Slic3r::Print->new;
@ -132,7 +132,7 @@ sub new {
}
}
$self->{list} = Wx::ListView->new($self, -1, wxDefaultPosition, wxDefaultSize, wxLC_SINGLE_SEL | wxLC_REPORT | wxBORDER_SUNKEN | wxTAB_TRAVERSAL | wxWANTS_CHARS);
$self->{list} = Wx::ListView->new($self, -1, wxDefaultPosition, [250,-1], wxLC_SINGLE_SEL | wxLC_REPORT | wxBORDER_SUNKEN | wxTAB_TRAVERSAL | wxWANTS_CHARS);
$self->{list}->InsertColumn(0, "Name", wxLIST_FORMAT_LEFT, 145);
$self->{list}->InsertColumn(1, "Copies", wxLIST_FORMAT_CENTER, 45);
$self->{list}->InsertColumn(2, "Scale", wxLIST_FORMAT_CENTER, wxLIST_AUTOSIZE_USEHEADER);
@ -284,6 +284,7 @@ sub new {
{
my $box = Wx::StaticBox->new($self, -1, "Info");
$object_info_sizer = Wx::StaticBoxSizer->new($box, wxVERTICAL);
$object_info_sizer->SetMinSize([350,-1]);
my $grid_sizer = Wx::FlexGridSizer->new(3, 4, 5, 5);
$grid_sizer->SetFlexibleDirection(wxHORIZONTAL);
$grid_sizer->AddGrowableCol(1, 1);
@ -299,14 +300,14 @@ sub new {
);
while (my $field = shift @info) {
my $label = shift @info;
my $text = Wx::StaticText->new($self, -1, "$label:", wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
my $text = Wx::StaticText->new($box, -1, "$label:", wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
$text->SetFont($Slic3r::GUI::small_font);
$grid_sizer->Add($text, 0);
$self->{"object_info_$field"} = Wx::StaticText->new($self, -1, "", wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
$self->{"object_info_$field"} = Wx::StaticText->new($box, -1, "", wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
$self->{"object_info_$field"}->SetFont($Slic3r::GUI::small_font);
if ($field eq 'manifold') {
$self->{object_info_manifold_warning_icon} = Wx::StaticBitmap->new($self, -1, Wx::Bitmap->new("$Slic3r::var/error.png", wxBITMAP_TYPE_PNG));
$self->{object_info_manifold_warning_icon} = Wx::StaticBitmap->new($box, -1, Wx::Bitmap->new("$Slic3r::var/error.png", wxBITMAP_TYPE_PNG));
$self->{object_info_manifold_warning_icon}->Hide;
my $h_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
@ -676,7 +677,7 @@ sub changescale {
sub arrange {
my $self = shift;
my $bb = Slic3r::Polygon->new_scale(@{$self->{config}->bed_shape})->bounding_box;
my $bb = Slic3r::Geometry::BoundingBoxf->new_from_points($self->{config}->bed_shape);
eval {
$self->{model}->arrange_objects($self->GetFrame->config->min_object_distance, $bb);
};
@ -752,7 +753,8 @@ sub split_object {
sub schedule_background_process {
my ($self) = @_;
$self->{apply_config_timer}->Start(PROCESS_DELAY, 1); # 1 = one shot
$self->{apply_config_timer}->Start(PROCESS_DELAY, 1) # 1 = one shot
if defined $self->{apply_config_timer};
}
sub async_apply_config {
@ -835,7 +837,7 @@ sub start_background_process {
sub stop_background_process {
my ($self) = @_;
$self->{apply_config_timer}->Stop;
$self->{apply_config_timer}->Stop if defined $self->{apply_config_timer};
$self->statusbar->SetCancelCallback(undef);
$self->statusbar->StopBusy;
$self->statusbar->SetStatusText("");
@ -1141,7 +1143,7 @@ sub on_config_change {
$self->Layout;
} elsif ($self->{config}->has($opt_key)) {
$self->{config}->set($opt_key, $value);
if ($opt_key eq 'bed_size') {
if ($opt_key eq 'bed_shape') {
$self->{canvas}->update_bed_size;
$self->update;
}

View file

@ -221,8 +221,8 @@ sub mouse_event {
my $model_object = $self->{model}->objects->[$obj_idx];
$model_object->instances->[$instance_idx]->set_offset(
Slic3r::Pointf->new(
unscale($pos->[X] - $self->{drag_start_pos}[X]),
unscale($pos->[Y] - $self->{drag_start_pos}[Y]),
unscale($point->[X] - $self->{drag_start_pos}[X]),
unscale($point->[Y] - $self->{drag_start_pos}[Y]),
));
$model_object->update_bounding_box;
$self->Refresh;
@ -305,14 +305,11 @@ sub scaled_points_to_pixel {
sub point_to_model_units {
my ($self, $point) = @_;
my $canvas_height = $self->GetSize->GetHeight;
my $zero = $self->{bed_origin};
my $p = Slic3r::Point->new(
return Slic3r::Point->new(
scale ($point->[X] - $zero->[X]) / $self->{scaling_factor},
scale ($point->[Y] - $zero->[Y]) / $self->{scaling_factor},
scale ($zero->[Y] - $point->[Y]) / $self->{scaling_factor},
);
use XXX; YYY $p->pp;
return $p;
}
1;

View file

@ -18,6 +18,7 @@ BoundingBoxBase<PointClass>::BoundingBoxBase(const std::vector<PointClass> &poin
}
}
template BoundingBoxBase<Point>::BoundingBoxBase(const std::vector<Point> &points);
template BoundingBoxBase<Pointf>::BoundingBoxBase(const std::vector<Pointf> &points);
template <class PointClass>
BoundingBox3Base<PointClass>::BoundingBox3Base(const std::vector<PointClass> &points)
@ -65,6 +66,7 @@ BoundingBoxBase<PointClass>::scale(double factor)
this->max.scale(factor);
}
template void BoundingBoxBase<Point>::scale(double factor);
template void BoundingBoxBase<Pointf>::scale(double factor);
template void BoundingBoxBase<Pointf3>::scale(double factor);
template <class PointClass> void
@ -76,6 +78,7 @@ BoundingBoxBase<PointClass>::merge(const PointClass &point)
this->max.y = std::max(point.y, this->max.y);
}
template void BoundingBoxBase<Point>::merge(const Point &point);
template void BoundingBoxBase<Pointf>::merge(const Pointf &point);
template <class PointClass> void
BoundingBoxBase<PointClass>::merge(const BoundingBoxBase<PointClass> &bb)
@ -86,6 +89,7 @@ BoundingBoxBase<PointClass>::merge(const BoundingBoxBase<PointClass> &bb)
this->max.y = std::max(bb.max.y, this->max.y);
}
template void BoundingBoxBase<Point>::merge(const BoundingBoxBase<Point> &bb);
template void BoundingBoxBase<Pointf>::merge(const BoundingBoxBase<Pointf> &bb);
template <class PointClass> void
BoundingBox3Base<PointClass>::merge(const PointClass &point)
@ -111,6 +115,7 @@ BoundingBoxBase<PointClass>::size() const
return PointClass(this->max.x - this->min.x, this->max.y - this->min.y);
}
template Point BoundingBoxBase<Point>::size() const;
template Pointf BoundingBoxBase<Pointf>::size() const;
template <class PointClass> PointClass
BoundingBox3Base<PointClass>::size() const
@ -126,6 +131,7 @@ BoundingBoxBase<PointClass>::translate(coordf_t x, coordf_t y)
this->max.translate(x, y);
}
template void BoundingBoxBase<Point>::translate(coordf_t x, coordf_t y);
template void BoundingBoxBase<Pointf>::translate(coordf_t x, coordf_t y);
template <class PointClass> void
BoundingBox3Base<PointClass>::translate(coordf_t x, coordf_t y, coordf_t z)
@ -144,6 +150,7 @@ BoundingBoxBase<PointClass>::center() const
);
}
template Point BoundingBoxBase<Point>::center() const;
template Pointf BoundingBoxBase<Pointf>::center() const;
template <class PointClass> PointClass
BoundingBox3Base<PointClass>::center() const

View file

@ -53,10 +53,15 @@ class BoundingBox : public BoundingBoxBase<Point>
};
/*
class BoundingBoxf : public BoundingBoxBase<Pointf> {};
class BoundingBox3 : public BoundingBox3Base<Point3> {};
*/
class BoundingBoxf : public BoundingBoxBase<Pointf> {
public:
BoundingBoxf() {};
BoundingBoxf(const std::vector<Pointf> &points) : BoundingBoxBase<Pointf>(points) {};
};
class BoundingBoxf3 : public BoundingBox3Base<Pointf3> {
public:
BoundingBoxf3() {};

View file

@ -293,6 +293,18 @@ Pointf::from_SV(SV* point_sv)
this->y = SvNV(sv_y);
return true;
}
void
Pointf::from_SV_check(SV* point_sv)
{
if (sv_isobject(point_sv) && (SvTYPE(SvRV(point_sv)) == SVt_PVMG)) {
if (!sv_isa(point_sv, perl_class_name(this)) && !sv_isa(point_sv, perl_class_name_ref(this)))
CONFESS("Not a valid %s object (got %s)", perl_class_name(this), HvNAME(SvSTASH(SvRV(point_sv))));
*this = *(Pointf*)SvIV((SV*)SvRV( point_sv ));
} else {
this->from_SV(point_sv);
}
}
#endif
void

View file

@ -74,6 +74,7 @@ class Pointf
#ifdef SLIC3RXS
bool from_SV(SV* point_sv);
void from_SV_check(SV* point_sv);
SV* to_SV_pureperl() const;
#endif
};

View file

@ -20,10 +20,10 @@
Clone<Point> center();
Clone<Point> min_point() %code{% RETVAL = THIS->min; %};
Clone<Point> max_point() %code{% RETVAL = THIS->max; %};
double x_min() %code{% RETVAL = THIS->min.x; %};
double x_max() %code{% RETVAL = THIS->max.x; %};
double y_min() %code{% RETVAL = THIS->min.y; %};
double y_max() %code{% RETVAL = THIS->max.y; %};
long x_min() %code{% RETVAL = THIS->min.x; %};
long x_max() %code{% RETVAL = THIS->max.x; %};
long y_min() %code{% RETVAL = THIS->min.y; %};
long y_max() %code{% RETVAL = THIS->max.y; %};
%{
@ -39,6 +39,37 @@ new_from_points(CLASS, points)
%}
};
%name{Slic3r::Geometry::BoundingBoxf} class BoundingBoxf {
~BoundingBoxf();
Clone<BoundingBoxf> clone()
%code{% RETVAL = THIS; %};
void merge(BoundingBoxf* bb) %code{% THIS->merge(*bb); %};
void merge_point(Pointf* point) %code{% THIS->merge(*point); %};
void scale(double factor);
void translate(double x, double y);
Clone<Pointf> size();
Clone<Pointf> center();
Clone<Pointf> min_point() %code{% RETVAL = THIS->min; %};
Clone<Pointf> max_point() %code{% RETVAL = THIS->max; %};
double x_min() %code{% RETVAL = THIS->min.x; %};
double x_max() %code{% RETVAL = THIS->max.x; %};
double y_min() %code{% RETVAL = THIS->min.y; %};
double y_max() %code{% RETVAL = THIS->max.y; %};
%{
BoundingBoxf*
new_from_points(CLASS, points)
char* CLASS
Pointfs points
CODE:
RETVAL = new BoundingBoxf(points);
OUTPUT:
RETVAL
%}
};
%name{Slic3r::Geometry::BoundingBoxf3} class BoundingBoxf3 {
~BoundingBoxf3();
Clone<BoundingBoxf3> clone()

View file

@ -12,6 +12,10 @@ BoundingBox* O_OBJECT_SLIC3R
Ref<BoundingBox> O_OBJECT_SLIC3R_T
Clone<BoundingBox> O_OBJECT_SLIC3R_T
BoundingBoxf* O_OBJECT_SLIC3R
Ref<BoundingBoxf> O_OBJECT_SLIC3R_T
Clone<BoundingBoxf> O_OBJECT_SLIC3R_T
BoundingBoxf3* O_OBJECT_SLIC3R
Ref<BoundingBoxf3> O_OBJECT_SLIC3R_T
Clone<BoundingBoxf3> O_OBJECT_SLIC3R_T

View file

@ -28,6 +28,9 @@
%typemap{BoundingBox*};
%typemap{Ref<BoundingBox>}{simple};
%typemap{Clone<BoundingBox>}{simple};
%typemap{BoundingBoxf*};
%typemap{Ref<BoundingBoxf>}{simple};
%typemap{Clone<BoundingBoxf>}{simple};
%typemap{BoundingBoxf3*};
%typemap{Ref<BoundingBoxf3>}{simple};
%typemap{Clone<BoundingBoxf3>}{simple};