From 250ff451ba337a154b5de4ca5d16b425a55a5166 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Mon, 24 Oct 2016 14:07:38 +0200 Subject: [PATCH] by alexrj: Fixes in GCodeSender to reset the connection after it breaks. by alexrj: Fix in mouse handling of 2DBed. by alexrj: ClipperUtils for ExPolygon vs. ExPolygon --- lib/Slic3r/GUI/2DBed.pm | 5 ++++- xs/src/libslic3r/ClipperUtils.cpp | 29 +++++++++++++++++++++++++++++ xs/src/libslic3r/ClipperUtils.hpp | 1 + xs/src/libslic3r/GCodeSender.cpp | 6 +++++- 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/lib/Slic3r/GUI/2DBed.pm b/lib/Slic3r/GUI/2DBed.pm index 3f116cf9c..388bc5a3a 100644 --- a/lib/Slic3r/GUI/2DBed.pm +++ b/lib/Slic3r/GUI/2DBed.pm @@ -11,7 +11,7 @@ use Wx qw(:misc :pen :brush :font :systemsettings wxTAB_TRAVERSAL wxSOLID); use Wx::Event qw(EVT_PAINT EVT_ERASE_BACKGROUND EVT_MOUSE_EVENTS EVT_SIZE); use base qw(Wx::Panel Class::Accessor); -__PACKAGE__->mk_accessors(qw(bed_shape interactive pos _scale_factor _shift on_move)); +__PACKAGE__->mk_accessors(qw(bed_shape interactive pos _scale_factor _shift on_move _painted)); sub new { my ($class, $parent, $bed_shape) = @_; @@ -165,12 +165,15 @@ sub _repaint { $dc->DrawLine($pos_px->[X]-15, $pos_px->[Y], $pos_px->[X]+15, $pos_px->[Y]); $dc->DrawLine($pos_px->[X], $pos_px->[Y]-15, $pos_px->[X], $pos_px->[Y]+15); } + + $self->_painted(1); } sub _mouse_event { my ($self, $event) = @_; return if !$self->interactive; + return if !$self->_painted; my $pos = $event->GetPosition; my $point = $self->to_units([ $pos->x, $pos->y ]); #]] diff --git a/xs/src/libslic3r/ClipperUtils.cpp b/xs/src/libslic3r/ClipperUtils.cpp index b97f7dfb2..f68610849 100644 --- a/xs/src/libslic3r/ClipperUtils.cpp +++ b/xs/src/libslic3r/ClipperUtils.cpp @@ -592,6 +592,17 @@ void diff(const SubjectType &subject, const Slic3r::ExPolygons &clip, ResultType } template void diff(const Slic3r::Polygons &subject, const Slic3r::ExPolygons &clip, Slic3r::ExPolygons* retval, bool safety_offset_); +template +void diff(const Slic3r::ExPolygons &subject, const Slic3r::ExPolygons &clip, ResultType* retval, bool safety_offset_) +{ + Slic3r::Polygons pp; + for (Slic3r::ExPolygons::const_iterator ex = subject.begin(); ex != subject.end(); ++ex) { + Slic3r::Polygons ppp = *ex; + pp.insert(pp.end(), ppp.begin(), ppp.end()); + } + diff(pp, clip, retval, safety_offset_); +} + Slic3r::Polygons diff(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool safety_offset_) { @@ -610,6 +621,7 @@ diff_ex(const SubjectType &subject, const ClipType &clip, bool safety_offset_) } template Slic3r::ExPolygons diff_ex(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool safety_offset_); template Slic3r::ExPolygons diff_ex(const Slic3r::Polygons &subject, const Slic3r::ExPolygons &clip, bool safety_offset_); +template Slic3r::ExPolygons diff_ex(const Slic3r::ExPolygons &subject, const Slic3r::ExPolygons &clip, bool safety_offset_); template void intersection(const SubjectType &subject, const Slic3r::Polygons &clip, ResultType* retval, bool safety_offset_) @@ -702,6 +714,23 @@ void union_(const Slic3r::Polygons &subject1, const Slic3r::Polygons &subject2, union_(pp, retval, safety_offset); } +Slic3r::Polygons +union_(const Slic3r::ExPolygons &subject1, const Slic3r::ExPolygons &subject2, bool safety_offset) +{ + Polygons pp; + for (Slic3r::ExPolygons::const_iterator it = subject1.begin(); it != subject1.end(); ++it) { + Polygons spp = *it; + pp.insert(pp.end(), spp.begin(), spp.end()); + } + for (Slic3r::ExPolygons::const_iterator it = subject2.begin(); it != subject2.end(); ++it) { + Polygons spp = *it; + pp.insert(pp.end(), spp.begin(), spp.end()); + } + Polygons retval; + union_(pp, &retval, safety_offset); + return retval; +} + void union_pt(const Slic3r::Polygons &subject, ClipperLib::PolyTree* retval, bool safety_offset_) { Slic3r::Polygons clip; diff --git a/xs/src/libslic3r/ClipperUtils.hpp b/xs/src/libslic3r/ClipperUtils.hpp index 9f3fca9e9..00b7a56a7 100644 --- a/xs/src/libslic3r/ClipperUtils.hpp +++ b/xs/src/libslic3r/ClipperUtils.hpp @@ -141,6 +141,7 @@ Slic3r::ExPolygons union_ex(const Slic3r::Polygons &subject, bool safety_offset Slic3r::ExPolygons union_ex(const Slic3r::Surfaces &subject, bool safety_offset = false); void union_(const Slic3r::Polygons &subject1, const Slic3r::Polygons &subject2, Slic3r::Polygons* retval, bool safety_offset = false); +Slic3r::Polygons union_(const Slic3r::ExPolygons &subject1, const Slic3r::ExPolygons &subject2, bool safety_offset = false); void union_pt(const Slic3r::Polygons &subject, ClipperLib::PolyTree* retval, bool safety_offset_ = false); void union_pt_chained(const Slic3r::Polygons &subject, Slic3r::Polygons* retval, bool safety_offset_ = false); diff --git a/xs/src/libslic3r/GCodeSender.cpp b/xs/src/libslic3r/GCodeSender.cpp index e2e8e4d90..963949ba2 100644 --- a/xs/src/libslic3r/GCodeSender.cpp +++ b/xs/src/libslic3r/GCodeSender.cpp @@ -69,7 +69,11 @@ GCodeSender::connect(std::string devname, unsigned int baud_rate) this->set_baud_rate(baud_rate); this->open = true; this->reset(); - + + // a reset firmware expect line numbers to start again from 1 + this->sent = 0; + this->last_sent.clear(); + /* Initialize debugger */ #ifdef DEBUG_SERIAL fs.open("serial.txt", std::fstream::out | std::fstream::trunc);