@@ -92,7 +92,6 @@ arc_welder::arc_welder(
9292	arcs_created_ = 0 ;
9393	waiting_for_arc_ = false ;
9494	previous_feedrate_ = -1 ;
95- 	previous_is_extruder_relative_ = false ;
9695	gcode_position_args_.set_num_extruders (8 );
9796	for  (int  index = 0 ; index < 8 ; index++)
9897	{
@@ -386,6 +385,7 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
386385	p_source_position_->update (cmd, lines_processed_, gcodes_processed_, -1 );
387386	position* p_cur_pos = p_source_position_->get_current_position_ptr ();
388387	position* p_pre_pos = p_source_position_->get_previous_position_ptr ();
388+ 	bool  is_previous_extruder_relative = p_pre_pos->is_extruder_relative ;
389389	extruder extruder_current = p_cur_pos->get_current_extruder ();
390390	extruder previous_extruder = p_pre_pos->get_current_extruder ();
391391	// std::cout << lines_processed_ << " - " << cmd.gcode << ", CurrentEAbsolute: " << cur_extruder.e <<", ExtrusionLength: " << cur_extruder.extrusion_length << ", Retraction Length: " << cur_extruder.retraction_length << ", IsExtruding: " << cur_extruder.is_extruding << ", IsRetracting: " << cur_extruder.is_retracting << ".\n";
@@ -455,7 +455,7 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
455455				//  we can get more arcs.
456456				(previous_extruder.is_retracting  && extruder_current.is_retracting )
457457			) &&
458- 			p_cur_pos->is_extruder_relative  == p_pre_pos-> is_extruder_relative  &&
458+ 			p_cur_pos->is_extruder_relative  == is_previous_extruder_relative  &&
459459			(!waiting_for_arc_ || p_pre_pos->f  == p_cur_pos->f ) && //  might need to skip the waiting for arc check...
460460			(!waiting_for_arc_ || p_pre_pos->feature_type_tag  == p_cur_pos->feature_type_tag )
461461			)
@@ -464,7 +464,6 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
464464		printer_point p (p_cur_pos->get_gcode_x (), p_cur_pos->get_gcode_y (), p_cur_pos->get_gcode_z (), extruder_current.e_relative , movement_length_mm);
465465		if  (!waiting_for_arc_)
466466		{
467- 			previous_is_extruder_relative_ = p_pre_pos->is_extruder_relative ;
468467			if  (debug_logging_enabled_)
469468			{
470469				p_logger_->log (logger_type_, DEBUG, " Starting new arc from Gcode:" gcode );
@@ -581,6 +580,7 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
581580		}
582581	}
583582
583+ 	bool  arc_generated = false ;
584584	if  (!arc_added && !(cmd.is_empty  && cmd.comment .length () == 0 ))
585585	{
586586		if  (current_arc_.get_num_segments () < current_arc_.get_min_segments ()) {
@@ -604,10 +604,13 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
604604				points_compressed_ += current_arc_.get_num_segments ()-1 ;
605605				arcs_created_++; //  increment the number of generated arcs
606606				write_arc_gcodes (p_pre_pos->is_extruder_relative , p_pre_pos->f );
607+ 				//  Now clear the arc and flag the processor as not waiting for an arc
608+ 				waiting_for_arc_ = false ;
609+ 				arc_generated = true ;
610+ 				current_arc_.clear ();
607611				p_cur_pos = NULL ;
608612				p_pre_pos = NULL ;
609613
610- 
611614				//  Reprocess this line
612615				if  (!is_end)
613616				{
@@ -642,13 +645,16 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
642645
643646	if  (waiting_for_arc_ || !arc_added)
644647	{
645- 		position* cur_pos = p_source_position_->get_current_position_ptr ();
646- 		unwritten_commands_.push_back (unwritten_command (cur_pos, movement_length_mm));
648+ 		//  This might not work....
649+ 		// position* cur_pos = p_source_position_->get_current_position_ptr();
650+ 		
651+ 		unwritten_commands_.push_back (unwritten_command (cmd, is_previous_extruder_relative, movement_length_mm));
647652
648653	}
649- 	if  (!waiting_for_arc_)
654+ 	else   if  (!waiting_for_arc_)
650655	{
651656		write_unwritten_gcodes_to_file ();
657+ 		current_arc_.clear ();
652658	}
653659	return  lines_written;
654660}
@@ -660,9 +666,10 @@ void arc_welder::write_arc_gcodes(bool is_extruder_relative, double current_feed
660666	//  remove the same number of unwritten gcodes as there are arc segments, minus 1 for the start point
661667	//  Which isn't a movement
662668	//  note, skip the first point, it is the starting point
663- 	for  (int  index = 0 ; index < current_arc_.get_num_segments () - 1 ; index++)
669+ 	int  num_segments = current_arc_.get_num_segments () - 1 ;
670+ 	for  (int  index = 0 ; index < num_segments; index++)
664671	{
665- 		unwritten_commands_.pop_back ();
672+ 		while  (! unwritten_commands_.pop_back (). is_g1_g2 );
666673	}
667674
668675	//  Undo the current command, since it isn't included in the arc
@@ -675,7 +682,7 @@ void arc_welder::write_arc_gcodes(bool is_extruder_relative, double current_feed
675682
676683	//  Craete the arc gcode
677684	std::string gcode;
678- 	if  (previous_is_extruder_relative_ ) {
685+ 	if  (is_extruder_relative ) {
679686		gcode = get_arc_gcode_relative (current_feedrate, comment);
680687	}
681688
@@ -703,9 +710,7 @@ void arc_welder::write_arc_gcodes(bool is_extruder_relative, double current_feed
703710	//  now write the current arc to the file 
704711	write_gcode_to_file (gcode);
705712
706- 	//  Now clear the arc and flag the processor as not waiting for an arc
707- 	waiting_for_arc_ = false ;
708- 	current_arc_.clear ();
713+ 	
709714}
710715
711716std::string arc_welder::get_comment_for_arc ()
0 commit comments