コード例 #1
0
ファイル: gcode.cpp プロジェクト: Funny-DK/repsnapper
void GCode::drawCommands(const Settings &settings, uint start, uint end,
			 bool liveprinting, int linewidth, bool arrows, bool boundary)
{
  // if (gl_List < 0) {
  //   gl_List = glGenLists(1);
  //   glNewList(gl_List, GL_COMPILE);
  //   cerr << "list " << gl_List << endl;

	double LastE=0.0;
	bool extruderon = false;
	// Vector4f LastColor = Vector4f(0.0f,0.0f,0.0f,1.0f);
	Vector4f Color = Vector4f(0.0f,0.0f,0.0f,1.0f);

        glEnable(GL_BLEND);
        glDisable(GL_CULL_FACE);
        glDisable(GL_LIGHTING);
        uint n_cmds = commands.size();
	if (n_cmds==0) return;
	Vector3d defaultpos(0,0,0);
	Vector3d pos(0,0,0);

	bool relativeE = settings.Slicing.RelativeEcode;

	bool debug_arcs = settings.Display.DisplayDebugArcs;

	double extrusionwidth = 0;
	if (boundary)
	  extrusionwidth =
	    settings.Extruder.GetExtrudedMaterialWidth(settings.Slicing.LayerThickness);

	start = CLAMP (start, 0, n_cmds-1);
	end = CLAMP (end, 0, n_cmds-1);

	if (end<=start) return;

	// get starting point
	if (start>0) {
	  uint i = start;
	  while ((commands[i].is_value || commands[i].where == defaultpos) && i < end)
	    i++;
	  pos = commands[i].where;
        }

	// draw begin
	glPointSize(20);
	glBegin(GL_POINTS);
	//glColor4f(1.,0.1,0.1,ccol[3]);
	glVertex3dv((GLdouble*)&pos);
	glEnd();

	Vector3d last_extruder_offset = Vector3d::ZERO;

	(void) extruderon; // calm warnings
	for(uint i=start; i <= end; i++)
	{
	        Vector3d extruder_offset = Vector3d::ZERO;
	        //Vector3d next_extruder_offset = Vector3d::ZERO;

		// TO BE FIXED:
		if (!settings.Display.DebugGCodeOffset) { // show all together
		  extruder_offset = settings.get_extruder_offset(commands[i].extruder_no);
		  pos -= extruder_offset - last_extruder_offset;
		  last_extruder_offset = extruder_offset;
		}
		double extrwidth = extrusionwidth;
	        if (commands[i].is_value) continue;
		switch(commands[i].Code)
		{
		case SETSPEED:
		case ZMOVE:
		case EXTRUDERON:
			extruderon = true;
			break;
		case EXTRUDEROFF:
			extruderon = false;
			break;
		// case COORDINATEDMOTION3D: // old 3D gcode
		//   if (extruderon) {
		//     if (liveprinting) {
		//       Color = settings.Display.GCodePrintingColour;
		//     } else
		//       Color = settings.Display.GCodeExtrudeColour;
		//   }
		//   else {
		//     Color = settings.Display.GCodeMoveColour;
		//     extrwidth = 0;
		//   }
		//   commands[i].draw(pos, linewidth, Color, extrwidth,
		// 		   arrows, debug_arcs);
		//   LastE=commands[i].e;
		//   break;
		case ARC_CW:
		case ARC_CCW:
		  if (i==start) {
		    break; // don't draw arcs at beginning (wrong startpoint)
		  }
		case COORDINATEDMOTION:
		  {
		    double speed = commands[i].f;
		    double luma = 1.;
		    if( (!relativeE && commands[i].e == LastE)
			|| (relativeE && commands[i].e == 0) ) // move only
		      {
			if (settings.Display.DisplayGCodeMoves) {
			  luma = 0.3 + 0.7 * speed / settings.Hardware.MaxMoveSpeedXY / 60;
			  Color = settings.Display.GCodeMoveColour;
			  extrwidth = 0;
			} else {
			   pos = commands[i].where;
			   break;
			}
		      }
		    else
		      {
			luma = 0.3 + 0.7 * speed / settings.Extruder.MaxLineSpeed / 60;
			if (liveprinting) {
			  Color = settings.Display.GCodePrintingColour;
			} else {
			  Color = settings.Extruders[commands[i].extruder_no].DisplayColour;
			}
			if (settings.Display.DebugGCodeExtruders) {
			  ostringstream o; o << commands[i].extruder_no+1;
			  Render::draw_string( (pos + commands[i].where) / 2. + extruder_offset,
					       o.str());
			}
		      }
		    if (settings.Display.LuminanceShowsSpeed)
		      Color *= luma;
		    commands[i].draw(pos, extruder_offset, linewidth,
				     Color, extrwidth, arrows, debug_arcs);
		    LastE=commands[i].e;
		    break;
		  }
		case RAPIDMOTION:
		  {
		    Color = settings.Display.GCodeMoveColour;
		    commands[i].draw(pos, extruder_offset, 1, Color,
				     extrwidth, arrows, debug_arcs);
		    break;
		  }
		default:
			break; // ignored GCodes
		}
		//if(commands[i].Code != EXTRUDERON && commands[i].Code != EXTRUDEROFF)
		//pos = commands[i].where;
	}
	glLineWidth(1);
  //   glEndList();
  // }
  // glCallList(gl_List);
}
コード例 #2
0
void GCode::drawCommands(const Settings &settings, uint start, uint end,
			 bool liveprinting, int linewidth, bool arrows, bool boundary)
{
	double LastE=0.0;
	bool extruderon = false;
	// Vector4f LastColor = Vector4f(0.0f,0.0f,0.0f,1.0f);
	Vector4f Color = Vector4f(0.0f,0.0f,0.0f,1.0f);

        glEnable(GL_BLEND);
        glDisable(GL_CULL_FACE);
        glDisable(GL_LIGHTING);
        uint n_cmds = commands.size();
	if (n_cmds==0) return;
	Vector3d defaultpos(0,0,0);
	Vector3d pos(0,0,0);
	
	bool relativeE = settings.Slicing.RelativeEcode;

	bool debug_arcs = settings.Display.DisplayDebugArcs;

	double extrusionwidth = 0;
	if (boundary)
	  extrusionwidth = 
	    settings.Hardware.GetExtrudedMaterialWidth(settings.Hardware.LayerThickness);

	start = CLAMP (start, 0, n_cmds-1);
	end = CLAMP (end, 0, n_cmds-1);
	
	if (end<=start) return;

	// get starting point 
	if (start>0) {
	  uint i = start;
	  while ((commands[i].is_value || commands[i].where == defaultpos) && i < end)
	    i++;
	  pos = commands[i].where;
        }

	// draw begin
	glPointSize(20);
	glBegin(GL_POINTS);
	//glColor4f(1.,0.1,0.1,ccol[3]);
	glVertex3dv((GLdouble*)&pos);    
	glEnd();
	
	for(uint i=start; i <= end; i++)
	{
	  double extrwidth = extrusionwidth;
	  if (commands[i].is_value) continue;
		switch(commands[i].Code)
		{
		case SETSPEED:
		case ZMOVE:
		case EXTRUDERON:
			extruderon = true;
			break;
		case EXTRUDEROFF:
			extruderon = false;
			break;
		case COORDINATEDMOTION3D: // old 3D gcode
		  if (extruderon) {
		    if (liveprinting) {
		      Color = settings.Display.GCodePrintingRGBA;
		    } else
		      Color = settings.Display.GCodeExtrudeRGBA;
		  }
		  else {
		    Color = settings.Display.GCodeMoveRGBA;
		    extrwidth = 0;
		  }
		  commands[i].draw(pos, linewidth, Color, extrwidth, 
				   arrows, debug_arcs);
		  LastE=commands[i].e;
		  break;
		case ARC_CW:
		case ARC_CCW:
		  if (i==start) {
		    break; // don't draw arcs at beginning (wrong startpoint)
		  }
		case COORDINATEDMOTION:
		  {
		    double speed = commands[i].f;
		    double luma = 1.;
		    if( (!relativeE && commands[i].e == LastE)
			|| (relativeE && commands[i].e == 0) )
		      {
			luma = 0.3 + 0.7 * speed / settings.Hardware.MoveSpeed;
			Color = settings.Display.GCodeMoveRGBA;
			extrwidth = 0;
		      }
		    else
		      {
			luma = 0.3 + 0.7 * speed / settings.Hardware.MaxPrintSpeedXY;
			if (liveprinting) {
			  Color = settings.Display.GCodePrintingRGBA;
			} else
			  Color = settings.Display.GCodeExtrudeRGBA;
		      }
		    if(settings.Display.LuminanceShowsSpeed)
		      Color *= luma;
		    commands[i].draw(pos, linewidth, Color, extrwidth,
				     arrows, debug_arcs);
		    LastE=commands[i].e;
		    break;
		  }
		case RAPIDMOTION:
		  commands[i].draw(pos, 1, Color, extrwidth, arrows, debug_arcs);
			break;
		default:
			break; // ignored GCodes
		}
		if(commands[i].Code != EXTRUDERON && commands[i].Code != EXTRUDEROFF)
		  pos = commands[i].where;
	}
	glLineWidth(1);
}