'Callback when a printer gcode is about to be sent. We use it to
exclude moves defined by the part excluder tool'

def preprintsendcb(self, gline, next_gline):

    if (not self.is_excluded_move(gline)):
        return gline
    else:
        if (gline.z is not None):
            if gline.relative:
                if (self.excluder_z_abs is not None):
                    self.excluder_z_abs += gline.z
                elif (self.excluder_z_rel is not None):
                    self.excluder_z_rel += gline.z
                else:
                    self.excluder_z_rel = gline.z
            else:
                self.excluder_z_rel = None
                self.excluder_z_abs = gline.z
        if ((gline.e is not None) and (not gline.relative_e)):
            self.excluder_e = gline.e
        if ((next_gline is not None) and (not self.is_excluded_move(next_gline))):
            if (self.excluder_e is not None):
                self.p.send_now(('G92    E%.5f' % self.excluder_e))
                self.excluder_e = None
            if (self.excluder_z_abs is not None):
                if gline.relative:
                    self.p.send_now('G90')
                self.p.send_now(('G1    Z%.5f' % self.excluder_z_abs))
                self.excluder_z_abs = None
                if gline.relative:
                    self.p.send_now('G91')
            if (self.excluder_z_rel is not None):
                if (not gline.relative):
                    self.p.send_now('G91')
                self.p.send_now(('G1    Z%.5f' % self.excluder_z_rel))
                self.excluder_z_rel = None
                if (not gline.relative):
                    self.p.send_now('G90')
            return None
